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 emails you at 80% of your ceiling, while you can still do something about it. It takes a handful of lines, and it's where the Well-Architected cost pillar starts.

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 the email lands while there's still time to act. start_date has to be the first of a month. Add another notification block for a 100% or a forecast alert.

Later you can add a budget per landing zone (a governed Azure setup that workloads run in) and wire alerts to an action group.

The full, runnable version is in the blog-examples repo.

discuss on linkedin → more writing