DFdom@fradley
← ~/writing
$ cat budget-alerts-as-code.md

Never get surprised by the Azure bill: budget alerts as code

The worst way to learn your Azure spend doubled is the invoice. A budget with an alert turns that into an email at 80%, while you can still do something about it. It takes a handful of lines, and the Well-Architected cost pillar starts exactly here: know what you're spending before it spends you.

Here's a monthly budget with an alert, in Terraform so it lives in a repo:

data "azurerm_subscription" "current" {}

resource "azurerm_consumption_budget_subscription" "monthly_cap" {
  name            = "monthly-cap"
  subscription_id = data.azurerm_subscription.current.id
  amount          = 500
  time_grain      = "Monthly"

  time_period {
    start_date = "2026-08-01T00:00:00Z"
  }

  notification {
    enabled        = true
    threshold      = 80
    operator       = "GreaterThan"
    contact_emails = ["you@example.com"]
  }
}

Apply it:

terraform init && terraform apply

amount is your monthly ceiling. threshold = 80 fires the email at 80% of it, so you get a nudge rather than a shock. start_date has to be the first of a month. Add another notification block for a 100% or a forecast alert.

That's the whole thing. One budget, one email, and the cost pillar of WAF stops being theoretical.

At scale this becomes a budget per landing zone, alerts wired to an action group, and a FinOps review that reads them. You don't need any of that yet. Ship one budget today.

Next: a one-line lock that stops anyone deleting prod by accident.

discuss on linkedin → more writing