Lesson 3 of 5 Governance Solutions

Building an Enforceable Tagging Strategy

This lesson explains how tags behave, what they should record, and how to keep them accurate.

Learning outcomes

After completing this lesson, you will be able to:

  • Describe tag limits and inheritance behaviour.
  • Identify useful types of tags.
  • Explain how Azure Policy enforces and copies tags.

How tags behave

A tag is a name and value pair attached to a resource, resource group or subscription, as metadata. Tags have no effect on how a resource behaves. Their value lies in what can be done with them: filtering costs, finding resources, and driving automation.

Several behaviours shape a tagging design. Each resource, resource group or subscription can have up to 50 tag name and value pairs. A tag name can be up to 512 characters and a value up to 256, although storage accounts limit names to 128. Tag names are not case sensitive, but values are. Most importantly, resources do not inherit the tags of their resource group or subscription, so a tag on a resource group does not appear on the resources within it.

True or false

Tag rules

Exam skills 1.3.1

Check the behaviours that shape a tagging design.

Log in to try this activity Interactive activities are free with an account.

What tags should record

A tag strategy starts by asking what questions the organization must answer. The Cloud Adoption Framework groups useful tags by their purpose.

Tag typeExample namesQuestion answered
Functionalapp, env, tierWhat is this resource, and what does it belong to?
Classificationconfidentiality, criticality, slaHow must it be protected and supported?
Accountingcost-centre, project, budgetWho pays for it?
Ownershipowner, business-unit, ops-teamWho is responsible for it?
Purposebusiness-process, revenue-impactWhy does it exist?

The list of required tags should be short, typically a handful. Each additional mandatory tag makes deployment more difficult and invites poor-quality data. Names and allowed values should be defined centrally, so that env=prod and environment=Production do not appear as separate categories in cost reports.

Sort into groups

Which kind of tag?

Exam skills 1.3.1

Classify each tag by the purpose it serves.

Log in to try this activity Interactive activities are free with an account.

Enforcing tags with Azure Policy

A tagging standard that relies on people remembering will fail, so Azure Policy should enforce it. Several built-in policy patterns are useful. Require a tag on resources uses the deny effect to reject deployments that lack the tag. Inherit a tag from the resource group uses the modify effect to copy the group's tag to its resources, closing the inheritance gap. A remediation task applies a modify policy to resources that existed before the assignment.

Deny policies should be introduced carefully, since they can block deployments that were not designed to include tags. A common route is to start with an audit effect to measure compliance, then move to modify or deny. Modify often gives a better experience than deny: a team sets a tag once on the resource group and every resource receives it automatically.

The following diagram shows the policies that produce a cost report by department with minimal change for developers.

Department cost reporting with minimal change for developers. A deny policy requires a department tag on every resource group; a built-in modify policy copies the tag from the resource group to each resource, with a remediation task for existing ones; and cost reports group by the tag.
The scenario is illustrative.

Tags and cost management

Tags feed Microsoft Cost Management, in which costs can be grouped and filtered by tag to produce showback or chargeback reports. Not every cost record supports tags, and tags do not apply retrospectively to costs from before the tag was added, which means tagging should begin early. Tag inheritance in Cost Management can apply subscription and resource group tags to usage records for reporting purposes, without changing the resources themselves.

Tags are not a security mechanism. They are stored in plain text and appear in logs and billing data, so they must never contain secrets or personal data. ABAC conditions can evaluate tags on blobs, but tags should not otherwise be relied on for access control.

Tags and naming conventions

Tags and resource names both carry information, and a design should decide what belongs where. A name is fixed for the life of most resources, and it has to satisfy each resource type's length and character rules. It should therefore contain only stable facts, such as the resource type, the workload, the environment and the region, as in st-orders-prod-weu-001. A tag can be changed at any time, so it should carry facts that may change, such as the owning team or a cost centre.

The Cloud Adoption Framework recommends agreeing naming and tagging together, before large deployments begin, and enforcing both through Azure Policy where possible. Allowed values should be limited, using a policy parameter that lists the valid environments, for example, so that reports do not fragment into near-duplicate categories.

Sort into groups

Name or tag?

Exam skills 1.3.1

Decide whether each fact belongs in the resource name or in a tag.

Log in to try this activity Interactive activities are free with an account.

Using tags for automation and operations

Tags also drive operations. A runbook can shut down virtual machines tagged for office hours, a backup policy can be applied through Azure Policy to machines with a given tag, and an update schedule can target machines by tag. Azure Resource Graph can query all resources in a tenant by tag, in seconds, which helps with inventory, audits and incident response, when a team must quickly find every resource belonging to an application.

Such uses raise the importance of accuracy, as an automation that depends on a wrong tag could stop the wrong server. A tag with operational effect should therefore be set by the deployment pipeline, and changes should be limited to people or processes that understand the effect, which can be arranged using the Tag Contributor role and Azure Policy.

Worked example

Reporting costs by department

A university needs a monthly cost report by department. Each department has several resource groups, and developers often forget to add tags to new resources. Costs must be attributed with minimal change to how developers work. What should you recommend?

A required department tag on each resource group, enforced by a policy with a deny effect at resource group level, establishes the data. A built-in policy with the modify effect then copies the tag from the resource group to each resource, so developers need not do anything further, and a remediation task handles existing resources.

Requiring the tag on each resource would achieve the result, but it would disrupt developers and reject many deployments. Tagging only resource groups without inheritance would leave costs unattributed in resource-level reports. Separate subscriptions for each department could work, but restructuring is a much larger change than the requirement justifies.

Check yourself

Which policy effect copies a tag from a resource group to the resources in it?

Show answer

Modify, with a remediation task for resources that already exist.

Exam Tips

Remember for the exam

  • Resources do not inherit tags without a policy or Cost Management tag inheritance.
  • Keep required tags few, with defined names and values.
  • Deny blocks untagged resources; modify copies tags; remediation fixes existing resources.
  • Never put secrets or personal data in tags.