Skip to main content

Terraform for dashboards

Configure all your Grafana dashboards and folders through terraform.

Advantages of managing dashboards as code​

  • They are version-controlled, making changes and rollbacks more transparent and trackable.
  • This approach allows you to standardize dashboard configurations across environments, eliminating manual errors and drift between staging and production. You can apply the same dashboard configuration across all your deployments / environments.
  • Terraform's declarative nature also makes it easy to spin up or tear down dashboards alongside your infrastructure, ensuring your monitoring visualizations evolve with your stack.
  • Integrating dashboard management into your CI/CD pipeline means faster, more reliable deployments, as your dashboards will always align with the infrastructure they monitor.

How​

info

Use oodle's Terraform Provider

Prerequisites​

To setup Oodle Dashboards via Terraform files, you'll need the following values:

  • OODLE_INSTANCE: Your Oodle instance ID. Go to Settings icon -> API Keys page in your Oodle UI to find out. (Oodle UI links: ap1, us1)
  • OODLE_API_KEY: Your Oodle API key for authentication. Go to Settings icon -> API Keys in your Oodle UI to choose an appropriate key. (Oodle UI links: ap1, us1)

Example usage​

terraform {
required_providers {
oodle = {
source = "registry.terraform.io/oodle-ai/oodle"
}
}
}

# These can also be set as environment variables:
# export OODLE_DEPLOYMENT=https://us1.oodle.ai/
# export OODLE_INSTANCE="my-instance"
# export OODLE_API_KEY="my-api-key"
provider "oodle" {
deployment_url = "https://us1.oodle.ai/"
instance = "my-instance"
api_key = "my-api-key"
}

# Example of creating a Grafana folder and dashboard together
# The dashboard references the folder's UID

resource "oodle_grafana_folder" "my_folder" {
title = "Test Folder"
}

resource "oodle_grafana_dashboard" "test_folder" {
folder = oodle_grafana_folder.my_folder.uid
config_json = jsonencode({
"title" : "My Dashboard Title",
"uid" : "my-dashboard-uid",
"schemaVersion" : 39,
"timezone" : "browser",
"panels" : [
{
"id" : 1,
"type" : "stat",
"title" : "Request Rate",
"gridPos" : {
"h" : 8,
"w" : 12,
"x" : 0,
"y" : 0
},
"targets" : [
{
"expr" : "sum(rate(http_requests_total[5m]))",
"refId" : "A"
}
]
},
{
"id" : 2,
"type" : "timeseries",
"title" : "Error Rate",
"gridPos" : {
"h" : 8,
"w" : 12,
"x" : 12,
"y" : 0
},
"targets" : [
{
"expr" : "sum(rate(http_requests_total{status=~\"5..\"}[5m])) / sum(rate(http_requests_total[5m]))",
"refId" : "A"
}
]
}
]
})
}

# Example of a dashboard with a commit message for version history
resource "oodle_grafana_dashboard" "service_dashboard" {
folder = oodle_grafana_folder.my_folder.uid
message = "Initial dashboard creation"
overwrite = true
config_json = jsonencode({
"title" : "Service Health",
"uid" : "service-health-dashboard",
"schemaVersion" : 39,
"time" : {
"from" : "now-6h",
"to" : "now"
},
"panels" : [
{
"id" : 1,
"type" : "gauge",
"title" : "Uptime",
"gridPos" : {
"h" : 8,
"w" : 8,
"x" : 0,
"y" : 0
},
"targets" : [
{
"expr" : "avg(up{job=\"my-service\"})",
"refId" : "A"
}
]
}
]
})
}

# Example without a folder (created at root level)
resource "oodle_grafana_dashboard" "root_dashboard" {
config_json = jsonencode({
"title" : "Root Level Dashboard",
"uid" : "root-level-dashboard",
"schemaVersion" : 39,
"panels" : []
})
}

Apply terraform configuration

terraform init
terraform apply

Support

If you need assistance or have any questions, please reach out to us through: