Module 5 · Dec 28 to Jan 1

Alerts as code

Dynatrace SLOs and alerts in Terraform, with locked remote state and reviewed pull requests.

0 of 5 bursts done

Concept in plain wordsAbout 2 minutes

Put each Dynatrace SLO and alert in Terraform, keep state in a locked remote backend, and change alerts only through a reviewed pull request. That gives you history, review and rollback for free. Each SLO or alert is one resource block: dynatrace_slo_v2 for SLOs, dynatrace_metric_events for alerts. terraform plan shows the change; terraform apply makes it. Export first: the provider can export existing Dynatrace config to code, so you start from what is live, not a blank page. A metric event looks at one-minute samples, opens a problem when enough samples in the window break the threshold, and closes when enough return to normal. Terraform remembers what it created in a state file, and locking stops two people applying at once.

Payments analogy: Alerts as code is dual control for monitoring: like a wire over a set amount needing a second approver, every alert change needs a reviewer, and the approval is logged with a timestamp.

Banking scenarioKnight Capital, Aug 1, 2012: the server nobody checked

What the source says

During the deployment of the new code, one of Knight's technicians did not copy the new code to one of the eight SMARS computer servers.

Knight did not have a second technician review this deployment and no one at Knight realized that the Power Peg code had not been removed from the eighth server, nor the new RLP code added. Knight had no written procedures that required such a review.

On August 1, Knight did not have supervisory procedures concerning incident response.

Source: SEC order, Release No. 70694 (Oct 16, 2013) needs internet

Illustrative scenario

Someone silences the "wire submission failures" alert in the monitoring UI during a noisy maintenance night and forgets to turn it back on. Three weeks later, wire submissions fail for 90 minutes and nobody is paged. The audit asks who changed the alert and when; the UI history has rolled off.

What an SRE would have seen first: During the incident, nothing, because the alert was off. Afterwards, a gap: no record of who changed it or why.

The control that would have caught it: The alert defined as a dynatrace_metric_events resource in Terraform, changed only by reviewed pull request with the plan attached, and a rule that manual UI edits get reverted.

Made-up payments translation for study. Not a real event at any company.

ThresholdsStarting points to tune, never mandates
SettingStarting valueSource
Metric event window5 one-minute samples, 3 violating to open, 5 normal to close
The provider's example, not a default.
dynatrace_metric_events docs needs internet
Alert on missing dataOff for sparse series, to avoid false alertsdynatrace_metric_events docs needs internet
SLO burn-rate alertStatic threshold of 10 to 14 on a -1h look-backDynatrace SLO docs needs internet
SLO target and warningWarning set slightly above target, for example target 99.9, warning 99.95estimate
API token scopesRead and write settings for alerts; plus read and write SLO for SLOs. Nothing more.dynatrace_slo_v2 docs needs internet
State lockingS3 backend with use_lockfile = true (default is false)Terraform S3 backend needs internet
State bucketVersioning onTerraform S3 backend needs internet
Reviewers per alert change1 besides the authorestimate
Rollback targetRestore the last good alert version in under 10 minutesestimate

Rows marked estimate have no published source. Test them against your own traffic.

Quiz3 scenario questions
1. terraform plan for your alerts repo shows it will modify the wires alert, but nobody changed the .tf file. What is most likely?

2. Where should the Dynatrace API token for your Terraform runs live?

3. Two engineers run terraform apply on the same alerts at the same moment. What prevents state corruption?

Try itDesktop exercise

Desktop Installing Terraform on your desktop is your call; use HashiCorp's own install steps. One file, one resource. No modules, no CI pipeline, no wrapper scripts this week.

  1. Write one .tf file with one Dynatrace resource: a burn-rate alert or an SLO from Module 2.
  2. Run terraform fmt and terraform validate.
  3. Run terraform plan only against a personal trial or sandbox tenant, never a work tenant. Do not apply unless you are sure what it changes.
  4. Write 5 lines on what the plan says it will create.

You keep: The .tf file plus your 5-line plan summary.

Verify notes

Read these

From your Sourced Reading Guide. Reading times in that guide are estimates.

Companion book estimate

Becoming a Rockstar SRE needs internet, Jeremy Proffitt and Rod Anami (Packt Publishing, April 28, 2023)

Mapped from chapter titles and the publisher's feature list only; I have not read the book, so treat each link as an estimate. Chapters 8 to 17 were not listed on the pages I opened. The book is from April 2023, so it predates the 2025 incidents and API docs used here; its code repo's software list names Prometheus and Grafana and does not name Dynatrace.