It's 3pm and finance asks which team owns a chunk of the Azure bill. You're staring at a resource group full of things with no owner tag, no costCenter, no clue.
Tags are labels you attach to a resource, such as owner or costCenter. They're one of the first governance jobs in the Cloud Adoption Framework, because without them you can't attribute cost, find owners, or tell production from a leftover experiment. Asking people to remember to tag things never works. Audit what's there first, then enforce the rule as code.
Move 1: find every untagged resource
Azure Resource Graph queries your whole estate in one go. This finds every resource missing an owner tag:
az graph query -q "Resources | where isnull(tags.owner) | project name, type, resourceGroup, location"
If the command isn't recognised, run az extension add --name resource-graph first. Run it on Monday morning and you have a worklist. Tomorrow someone creates ten more untagged resources, which is why the second move exists.
Move 2: enforce it with Azure Policy
Azure Policy checks resources in a scope (here, a subscription) against a rule. Every policy has an effect. Start with audit, which flags offenders and blocks nothing. Move to deny, which refuses to create anything without the tag, once you trust the rule.
This policy flags resource groups with no owner tag. It's written in Terraform, so it lives in a repo and gets reviewed in a pull request like any other change:
data "azurerm_subscription" "current" {}
resource "azurerm_policy_definition" "audit_owner_tag" {
name = "audit-missing-owner-tag"
policy_type = "Custom"
mode = "All"
display_name = "Audit resource groups missing an owner tag"
policy_rule = jsonencode({
if = {
allOf = [
{ field = "type", equals = "Microsoft.Resources/subscriptions/resourceGroups" },
{ field = "tags['owner']", exists = "false" }
]
}
then = { effect = "audit" }
})
}
resource "azurerm_subscription_policy_assignment" "audit_owner_tag" {
name = "audit-missing-owner-tag"
subscription_id = data.azurerm_subscription.current.id
policy_definition_id = azurerm_policy_definition.audit_owner_tag.id
display_name = "Audit resource groups missing an owner tag"
}
Apply it:
terraform init && terraform apply
The definition is the rule: if a resource is a resource group and has no owner tag, the effect is audit. The assignment switches that rule on for your subscription.
The routine afterwards
The policy continuously reports non-compliant resource groups. Find them under Policy, then Compliance in the portal, or run az policy state summarize, and work through the list. Once you trust it, flip the effect to deny so nobody can create an untagged resource in the first place.
Later you can group policies into initiatives (reusable sets applied across a management-group hierarchy) and add exemptions and remediation tasks. One policy is enough to start.
The full, runnable version is in the blog-examples repo.