Slide 4 of 4

Reliable, repeatable deployments

How Terraform handles existing dashboards

A reliable pipeline produces the same result no matter how many times you run it, with no duplicate dashboards and no errors. Terraform ensures this with a state file: a record of the resources it has created. On each run, Terraform decides what to change by comparing three things:

  • Your configuration
  • The state file
  • What actually exists in Grafana

When the live dashboard no longer matches your code (for example, someone edited it in the UI), that difference is called drift. Because of this, you can safely retry failed runs and merge to main repeatedly without creating duplicates.

ScenarioWhat Terraform does
Dashboard doesn’t existCreates it and records in state
Dashboard exists and matchesNo changes needed
Dashboard was edited manuallyDetects drift, restores code-defined version

Why stable UIDs matter

A stable UID in your DashboardBuilder gives Terraform a consistent identifier to track across runs. With it, Terraform updates the same dashboard each time. Without it, Terraform has nothing to match against, so each deployment creates a new dashboard and you get duplicates on every run.

Go
builder := dashboard.NewDashboardBuilder("My Dashboard").
  Uid("my-dashboard")  // Same UID = update, not duplicate

Script

A pipeline must be reliable. If you run it multiple times it must produce the same result without errors or duplicates. Terraform handles this automatically through state management.

Terraform tracks which resources it created in a state file. On each run, it compares your configuration to the current state and to what exists in Grafana. This three-way comparison lets Terraform detect drift. If someone manually edited a dashboard in the UI, Terraform will show the difference in its plan and restore the code-defined version on apply.

This is why setting a stable UID in your DashboardBuilder matters. It gives Terraform a consistent identifier to track. Without it, you’d get duplicates on every run.

The practical benefit: you can rerun your pipeline as many times as you want. Failed runs can be retried safely. Multiple merges to main won’t create duplicate dashboards. And manual edits in the UI get corrected on the next pipeline run.