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:
Create a new directory for your Terraform configuration (or use your existing project directory where
dashboard.jsonlives):mkdir -p terraform && cd terraformCreate a file named
main.tfwith the provider configuration: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 }Create a
terraform.tfvarsfile with your credentials (or pass them as environment variables):grafana_url = "https://your-stack.grafana.net/" grafana_token = "glsa_your_token_here"
Warning
Add
terraform.tfvarsto your.gitignoreto avoid committing credentials. For CI/CD, pass credentials as environment variables (TF_VAR_grafana_urlandTF_VAR_grafana_token) instead.
Initialize Terraform to download the Grafana provider:
terraform initYou should see output indicating that the
grafana/grafanaprovider was successfully installed.
What the provider supports
The provider supports Grafana Cloud, Enterprise, and OSS instances.
In the next milestone, you add a grafana_dashboard resource that references your JSON file.