Azure Cost and Tagging Guardrails
Catching missing ownership tags before deployment and defining an early budget alert.
Situation
I wanted lab resource groups to have a clear owner and environment, and I wanted a spending signal before the monthly budget was reached.
Task
I needed one check for planned resource groups and a separate budget notification for actual Azure spend.
Action
I used Terraform to define a resource group and a configurable monthly budget. I set an email notification at 80% of the configured amount, using actual consumption as the trigger. I documented that the notification does not stop resources or cap spending.
I wrote a Python check that reads Terraform plan JSON and examines the final values for Azure resource groups. I skip deletions and treat missing or blank owner and environment tags as violations. The output names the resource and the missing field so the author can fix the plan.
I added a passing example and a failing example to the repository. I wired GitHub Actions to run both fixtures and check that the rejected example exits with an error. A separate workflow checks that the Terraform configuration is valid.
What I would improve
I would integrate the checker with an actual sandbox plan, add tests for unknown tag values, and verify the budget and email destination in Azure.
Result
CI accepted the compliant plan fixture, rejected the fixture missing an owner tag, and passed Terraform validation. The 80% notification threshold is defined in code. Delivery in Azure still needs verification.