---
title: "Configure the Grafana Terraform provider | Grafana Labs"
description: "Learn how to declare your Grafana Terraform provider and connect."
---

> 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:
   
   Bash ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy
   
   ```bash
   mkdir -p terraform-alerts && cd terraform-alerts
   ```
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.

In the next milestone, you define a folder and an alert rule group.
