[Infrastructure as Code (IaC)] Manage Grafana with Terraform Grafana Provider
Terraform Grafana Provider
Examples about using Terraform Grafana Provider to manage Grafana resources.
Prerequsites
Your must have a Grafana admin account and password, and Terraform CLI have been installed.
Grafana Admin Account and Password
Account and password provide by Grafana.
Terrraform and Terrafrom Grafana Provider
-
Use Infrastructure as Code to provision and manage any cloud, infrastructure, or service
-
Provider: Grafana - Terraform by HashiCorp
The Grafana provider gives the ability to deploy and configure resources in a Grafana server.
Configuration
Grafana Provider Variables
First, Specify values for Grafana Provider variables within terraform.tfvars.
1 | url = "<Your Grafana URL>" |
Grafana Provider
1 | // Docs overview | grafana/grafana | Terraform Registry |
Run
Terraform Init
1 | terraform init |
It will download the Terraform Grafana Provider binary.
Terraform apply
1 | terraform apply |
It will dispaly the execute plan and wait for your make yes or no.
Then yes to create Grafana roles(users) and databases.
Terraform Resource
grafana_organization
Import the default grafana_organization
resource MainOrg
.
1 | terraform import grafana_organization.MainOrg 1 |
Then, create or edit grafana_organization.tf
file.
1 | # grafana_organization.tf |
grafana_user
1 | # grafana_user.tf |
grafana_team
1 | # grafana_team.tf |
grafana_folder
1 | # grafana_folder.tf |
grafana_dashboard
1 | # grafana_dashboard.tf |
1 | { |
Terraform destroy
1 | terraform destroy |
All resource objects will be destroyed.
FAQs
The dashboard has been changed by someone else
1 | │ Error: status: 412, body: {"message":"The dashboard has been changed by someone else","status":"version-mismatch"} |
Try to remove uid
field in the dashbord JSON file.
1 | - "uid": "dad2fs1", |
Reference
[3] Terraform by HashiCorp - https://www.terraform.io/
[4] Grafana: The open observability platform | Grafana Labs - https://grafana.com/