---
title: "Configure the Grafana Terraform provider | Grafana Labs"
description: "Write the Terraform configuration to declare and authenticate the Grafana provider."
---

> For a curated documentation index, see [llms.txt](/llms.txt). For the complete documentation index, see [llms-full.txt](/llms-full.txt).

# Configure the Grafana Terraform provider

The Grafana Terraform provider connects Terraform to your Grafana instance. You declare it in your Terraform configuration and supply the URL and service account token for authentication.

To configure the provider, complete the following steps:

1. Create a new directory for your Terraform configuration (or use your existing project directory where `dashboard.json` lives):
   
   Bash ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy
   
   ```bash
   mkdir -p terraform && cd terraform
   ```
2. Create a file named `main.tf` with the provider configuration:
   
   hcl ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy
   
   ```hcl
   terraform {
     required_providers {
       grafana = {
         source  = "grafana/grafana"
         version = ">= 2.9.0"
       }
     }
   }
   
   variable "grafana_url" {
     description = "Grafana instance URL"
     type        = string
   }
   
   variable "grafana_token" {
     description = "Grafana service account token"
     type        = string
     sensitive   = true
   }
   
   provider "grafana" {
     url  = var.grafana_url
     auth = var.grafana_token
   }
   ```
3. Create a `terraform.tfvars` file with your credentials (or pass them as environment variables):
   
   hcl ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy
   
   ```hcl
   grafana_url   = "https://your-stack.grafana.net/"
   grafana_token = "glsa_your_token_here"
   ```

> Warning
> 
> Add `terraform.tfvars` to your `.gitignore` to avoid committing credentials. For CI/CD, pass credentials as environment variables (`TF_VAR_grafana_url` and `TF_VAR_grafana_token`) instead.

1. Initialize Terraform to download the Grafana provider:
   
   Bash ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy
   
   ```bash
   terraform init
   ```
   
   You should see output indicating that the `grafana/grafana` provider was successfully installed.

## What the provider supports

Expand table

| Resource type        | Examples                              |
|----------------------|---------------------------------------|
| **Dashboards**       | Create, update, organize into folders |
| **Folders**          | Organize dashboards hierarchically    |
| **Data sources**     | Prometheus, Loki, Tempo, etc.         |
| **Alert rules**      | Alerting configurations               |
| **Service accounts** | API credentials                       |

The provider supports Grafana Cloud, Enterprise, and OSS instances.

In the next milestone, you add a `grafana_dashboard` resource that references your JSON file.
