# Dashboards as code

Hand-edited dashboards drift and nobody notices until the incident where the panel was deleted. Treat the dashboard as code: JSON in git, deployed by Terraform.

## The flow

1. Build the dashboard in the UI first (the builder is faster than hand-writing JSON).
2. Export the dashboard JSON and commit it. One dashboard per file, named for what it shows.
3. Deploy with the `datadog_dashboard` Terraform resource. From then on, edits go through the file and apply, not the UI.
4. Import existing dashboards into Terraform before converting (docs cover the import command) so you do not recreate or orphan them.

## Rules that keep it sane

- **Lock the UI**: team policy is no direct production dashboard edits. UI edits get overwritten on next apply anyway, which surprises people once.
- **Template variables**: use them for env/region/service so one dashboard serves all environments instead of N clones.
- **Standard widgets**: timeseries for rates, query values for SLOs, toplists for the hot offenders. Exotic widgets age badly.
- **Review dashboard diffs** like code: a PR that deletes half the panels should look alarming in review.

## Verify

Apply from a clean checkout reproduces the dashboard exactly. Change a panel in the file, apply, confirm the UI reflects it. Then try a UI edit and watch apply revert it (that is the point, do it once so the team believes it).