OnCallReadyStart learning

Azure Lesson 32.4 · Azure IV: Governance, Storage & Backup · 21 min read

Management groups, subscriptions, resource groups and tags at scale

In plain words

Imagine folders inside folders. The top folder is the whole company (the Tenant Root Group), inside it are department folders (management groups), inside those are budget binders (subscriptions), inside those are project boxes (resource groups), and in each box are the actual things (resources).

A sticker on a folder - "only these people may open this", "nothing red allowed" - applies to everything inside it. Name tags on boxes are the exception: a box's name tag is not copied onto the things in it.

Management groups, subscriptions, resource groups and tags at scale

Azure I treated a subscription as the top of the world: you logged in, picked one, made resource groups in it. A company has dozens of subscriptions: one per environment, per team, per product, a sandbox for every engineer. Nobody assigns roles or policies to fifty subscriptions one by one. They put the subscriptions in a tree of management groups and govern the tree. This lesson builds that tree, looks at what it changes for access, and covers the boring things that decide whether a cost report or a cleanup script works: resource groups, moves and tags.

Need to know: the scope hierarchy is management group › subscription › resource group › resource. Role assignments, Azure Policy assignments and locks made at one level are inherited by everything below it. The tree starts at the Tenant Root Group (its name is the tenant id), holds up to 6 levels of management groups under the root (not counting the root and the subscription level), and each subscription has exactly one parent.

Building the tree

$ az account management-group list -o table
DisplayName        Name                                  TenantId
-----------------  ------------------------------------  ------------------------------------
Tenant Root Group  11111111-2222-3333-4444-555555555555  11111111-2222-3333-4444-555555555555
$ az account management-group create -n mg-try-oncall -d "OnCall Lab" -o table
DisplayName  Name           TenantId
-----------  -------------  ------------------------------------
OnCall Lab   mg-try-oncall  11111111-2222-3333-4444-555555555555
$ az account management-group create -n mg-try-prod -d "Production" --parent mg-try-oncall --query "{name:name, parent:details.parent.name}"
{
  "name": "mg-try-prod",
  "parent": "mg-try-oncall"
}
$ az account management-group create -n mg-try-nonprod -d "Non-production" --parent mg-try-oncall -o none
$ az account list --query "[].{name:name, subscriptionId:id}" -o table
Name               SubscriptionId
-----------------  ------------------------------------
sub-oncall-lab     00000000-1111-2222-3333-444444444444
sub-platform-prod  00000000-1111-2222-3333-555555555555
$ az account management-group subscription add -n mg-try-nonprod -s sub-oncall-lab -o none
$ az account management-group subscription add -n mg-try-prod -s sub-platform-prod -o none
$ az account management-group show -n mg-try-oncall -e -r --query "children[].{group:name, subscriptions:children[].displayName}"
[
  {
    "group": "mg-try-prod",
    "subscriptions": [
      "sub-platform-prod"
    ]
  },
  {
    "group": "mg-try-nonprod",
    "subscriptions": [
      "sub-oncall-lab"
    ]
  }
]
  • -n is the group's id (part of its resource id and of every scope string). It can't be changed later. -d is the display name and can be.
  • -e -r (--expand --recurse) shows the whole subtree. Without them show returns only the group.
  • -o table never shows id, type or etag columns, even when your --query names them: name the key something else (subscriptionId:id) to see it.
  • A new subscription lands under the root group, or under the default management group if your organization set one (Settings on the root group). Put a mg-sandbox there with strict policies and new subscriptions are governed from their first minute.
  • Moving a subscription between management groups needs write access on the subscription and on both groups. The moment it moves, it gets the new parent's roles and policies and loses the old ones. That is a production change, so treat it like one.

What inheritance does to access

A role assigned at a management group reaches every subscription below it, now and later:

$ az ad group create --display-name try-sre-readers --mail-nickname try-sre-readers -o none
$ az role assignment create --assignee $(az ad group show --group try-sre-readers --query id -o tsv) --role Reader --scope /providers/Microsoft.Management/managementGroups/mg-try-prod -o none
$ az role assignment list --scope /subscriptions/00000000-1111-2222-3333-555555555555 --include-inherited --query "[].{who:principalName, role:roleDefinitionName, scope:scope}" -o table
Who                               Role    Scope
--------------------------------  ------  --------------------------------------------------------------
[email protected]  Reader  /subscriptions/00000000-1111-2222-3333-555555555555
[email protected]  Owner   /providers/Microsoft.Management/managementGroups/mg-try-oncall
[email protected]  Owner   /providers/Microsoft.Management/managementGroups/mg-try-prod
try-sre-readers                   Reader  /providers/Microsoft.Management/managementGroups/mg-try-prod

Two of those rows you made without noticing: whoever creates a management group gets Owner on it, and that Owner is inherited by everything you later put under it. --include-inherited is how you answer "why can this person see production?". Without it, list shows only the assignments made at that scope, and the one that matters sits two levels up. The scope column tells you where to go and remove it.

Subscriptions

A subscription is the billing and quota boundary: one invoice section, its own limits (vCPUs per region, public IPs...), its own RBAC root. The exam's "manage subscriptions" is mostly:

  • Create one: billing account (Enterprise Agreement, Microsoft Customer Agreement) and a role on it, or the portal's Subscriptions › Add. Large estates create them through subscription vending (an automated request process: ARM/Bicep or Terraform with the Microsoft.Subscription/aliases resource), already placed in the right management group.
  • Rename (portal, or the account CLI extension), transfer billing ownership to another billing account, move to another tenant (the role assignments do not follow: they are recreated in the new tenant), cancel (it is disabled first and deleted after about 90 days).
  • Switch between them in the CLI: every az command works on the current subscription unless you pass --subscription.
$ az account show --query "{name:name, id:id, tenant:tenantId}"
{
  "id": "00000000-1111-2222-3333-444444444444",
  "name": "sub-oncall-lab",
  "tenant": "11111111-2222-3333-4444-555555555555"
}
$ az account set -s sub-platform-prod
$ az account show --query name -o tsv
sub-platform-prod
$ az account set -s sub-oncall-lab

Scripts should pass --subscription on every call instead of relying on az account set. The current subscription is shared by every terminal on the machine, and a cleanup script run "in dev" right after someone switched to prod has caused more than one outage.

Resource groups

A resource group holds resources that share a lifecycle: you deploy them together and delete them together. Rules worth knowing:

  • Every resource is in exactly one resource group. A group can hold resources from any region; the group's own location is only where its metadata is kept.
  • az group delete deletes everything inside it, with no recycle bin (only resources with their own soft delete, like Key Vault or protected backup data, can be recovered). A lock is the guard (lesson after next).
  • Resources can move to another group or subscription: az resource move. The resource id changes (scripts and alerts that hold the old id break), the region does not. Some types can't move, and some need their dependencies moved with them (a VM with its disks and NIC).
$ az group create -n rg-try-gov -l westeurope --tags env=lab team=platform -o none
$ az group create -n rg-try-gov2 -l northeurope -o none
$ az storage account create -n sttrygov01 -g rg-try-gov --tags app=reports -o none
$ az resource move --destination-group rg-try-gov2 --ids $(az storage account show -n sttrygov01 -g rg-try-gov --query id -o tsv) 2>/dev/null
$ az storage account show -n sttrygov01 -g rg-try-gov2 --query "{rg:resourceGroup, location:location}"
{
  "location": "westeurope",
  "rg": "rg-try-gov2"
}

The account moved to a group in northeurope and is still in westeurope: a group's location says nothing about where its resources are.

Tags

A tag is a name/value pair on a resource, a resource group or a subscription: env=prod, team=payments, cost-center=4711. Cost reports group by them, cleanup scripts filter by them, on-call finds owners by them. Rules:

  • Up to 50 tags per resource. Names are case-insensitive, values are case-sensitive.
  • Tags are not inherited. A resource group tagged team=platform says nothing about the resources in it. (Cost Management can apply group tags to cost data, and Azure Policy can copy them onto resources: next lesson.)
  • Changing tags is a write on the resource: it needs write permission, and a ReadOnly lock blocks it.

Three commands, three behaviours:

$ ID=$(az storage account show -n sttrygov01 -g rg-try-gov2 --query id -o tsv)
$ az tag update --resource-id $ID --operation merge --tags cost-center=4711 --query properties.tags
{
  "app": "reports",
  "cost-center": "4711"
}
$ az tag update --resource-id $ID --operation delete --tags cost-center=4711 --query properties.tags
{
  "app": "reports"
}
$ az resource tag --ids $ID --tags owner=sre --query tags
{
  "owner": "sre"
}
$ az resource tag --ids $ID --tags app=reports -i --query tags
{
  "app": "reports",
  "owner": "sre"
}

That predict is the classic tagging incident: a script "adds" a tag with az resource tag (no -i), and wipes the cost-center tags finance reports on. Use az tag update --operation merge in scripts, unless you really mean replace.

Finding things by tag across the subscription:

$ az resource list --tag app=reports --query "[].{name:name, group:resourceGroup}" -o table
Name        Group
----------  -----------
sttrygov01  rg-try-gov2
$ az group list --query "[?tags.team=='platform'].name" -o tsv
rg-try-gov

On the exam (AZ-104 1.3.3-1.3.5, 1.3.7): management groups (hierarchy, 6 levels, root group, inheritance of RBAC and Policy, moving subscriptions), subscriptions (billing boundary, moving, transferring), resource groups (lifecycle, moving resources, deleting, locks), tags (not inherited, 50 per resource, merge vs replace, policy to enforce or inherit them).

In an interview: "How would you organise Azure for a company with many teams?" - "A management group tree by environment and purpose, for example platform, landing zones split into prod and non-prod, and a sandbox group, with subscriptions per team or workload below them. Roles go to Entra groups at the management group level, so they are inherited, and Azure Policy is assigned there too: allowed regions, required tags, no public IPs in prod. Tags on everything for owner, environment and cost centre, enforced by policy, so cost reports and on-call can find owners."

What you can now do

  • Build a management group tree, move subscriptions into it, and assign roles at the right level.
  • Find inherited access with az role assignment list --include-inherited.
  • Move resources between groups and say what changes (the id) and what does not (the region).
  • Tag with merge, replace or delete on purpose, and find resources by tag.

Why it helps

Without a structure, every role and every rule has to be applied subscription by subscription, and something is always missed. A management group tree lets the platform team set access and guardrails once and have them reach every subscription, including the ones created next year.

Tags are what make cost reports, cleanup jobs and "who owns this?" work, and the merge-versus-replace difference is behind more than one deleted cost-centre tag.

Commands in this lesson

az

FAQ

How deep can the management group tree go?

Six levels of management groups under the Tenant Root Group, not counting the root and the subscription level. A subscription has exactly one parent. In practice two or three levels are enough: organisation, platform versus landing zones, prod versus non-prod.

Why can I see resources I was never given access to?

Probably an assignment higher up: a role at a management group or subscription is inherited by everything below it. az role assignment list --scope <resource> --include-inherited shows assignments from above too, and the scope column says where to remove it.

Does moving a resource to another group change its region?

No. A move changes the resource id (the group, and the subscription if you move across subscriptions), never the region. Anything that uses the old id breaks: scripts, alerts, dashboards and role assignments, which do not move with it.

What is the difference between az tag update --operation merge and az resource tag?

merge adds or overwrites the tags you give and keeps the rest; replace (and az resource tag without -i) sets exactly the tags you give and drops the others; delete removes the ones you name. Scripts should use merge unless they really mean replace.

Should scripts use az account set?

Better not: the current subscription is shared by every shell on the machine, so a script can run against whatever someone else switched to. Pass --subscription on each call, or set it once at the start of the script and check it with az account show.

In an interview Mid

How would you organise subscriptions and access for a company with many teams?

A management group tree by environment and purpose (platform, prod and non-prod landing zones, sandbox) with subscriptions per team or workload. Roles are given to Entra groups at the management group so they are inherited, which I can check with az role assignment list --include-inherited. Azure Policy is assigned there too. Resource groups follow lifecycles. Tags for owner, environment and cost centre go on everything, enforced by policy, because tags are not inherited and cost reports depend on them.

Also asked: What does a management group give you that a subscription does not? · What happens to a resource's role assignments when you move it to another resource group? · Are tags inherited from the resource group?

Practise this lesson in the terminal Free, in your browser - a real Ubuntu terminal to try it in, with missions that check your work.