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"
]
}
]
-nis the group's id (part of its resource id and of every scope string). It can't be changed later.-dis the display name and can be.-e -r(--expand --recurse) shows the whole subtree. Without themshowreturns only the group.-o tablenever showsid,typeoretagcolumns, even when your--querynames 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-sandboxthere 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/aliasesresource), already placed in the right management group. - Rename (portal, or the
accountCLI 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
azcommand 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 deletedeletes 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=platformsays 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.