Overview and What You Will Learn
Azure organizes everything in a four-level tree of Management Groups, Subscriptions, Resource Groups, and Resources, and every resource belongs to exactly one Resource Group. In this lab, you will create tagged Resource Groups with a clear naming convention, see which settings inherit downward and which do not, move a resource between groups, and use a lock to stop an accidental delete.
Why This Matters in Production
A consistent hierarchy makes an Azure environment auditable, billable per team, and safe to clean up. Imagine a fast-growing company like Datadog with hundreds of resources in one subscription and no Resource Group structure. Nobody can tell which VM belongs to which project, cost reports become meaningless, and deleting a test environment risks taking down something in production.
Core Principles
A Resource Group is a logical container that holds no infrastructure itself, and it is flat, so groups cannot be nested. A Subscription is the billing and access boundary that holds many Resource Groups. A Management Group sits above subscriptions so you can apply access rules and policy to many of them at once. Management groups can be nested up to six levels deep, not counting the tenant root.
devops.in] --> M[Management Group
mg-production] M --> S[Subscription
sub-payments-prod] S --> G[Resource Group
rg-payments-prod-mumbai] G --> R[(VM, storage, VNet)] classDef top fill:#475569,color:#FFFFFF classDef mid fill:#8B5CF6,color:#FFFFFF classDef group fill:#326CE5,color:#FFFFFF classDef res fill:#10B981,color:#FFFFFF class T top class M,S mid class G group class R res
| Level | What it is | Typical use |
|---|---|---|
| Management Group | Container for subscriptions | Org-wide policy and access |
| Subscription | Billing and access boundary | One per team or environment |
| Resource Group | Logical container | One per app and environment |
Some settings flow down the tree and others do not, and mixing them up causes most hierarchy surprises:
- Role assignments (RBAC) inherit downward and are additive. A Contributor role granted on a Subscription applies to every group and resource beneath it, and a lower level cannot remove it.
- Azure Policy assignments inherit downward to everything in scope.
- Resource locks inherit downward, so a lock on a group protects every resource inside it.
- Tags do not inherit. Tagging a Resource Group does not tag its resources unless you add an Azure Policy that copies the tag.
RememberDeleting a Resource Group permanently deletes everything inside it, with no per-resource confirmation. Check what lives in a group before you delete it.
Detailed Step-by-Step Practical Lab
How to Check Your Subscription and Tenant
az account show --query "[name, id, tenantId]" --output tsvHow to List Your Management Groups
This step is read-only. If it returns an authorization error, your account has no management group access, which is fine for this lab.
az account management-group list --output tableHow to Name and Tag a Resource Group
Use a pattern like rg-<app>-<env>-<region>, so anyone can tell a group's purpose at a glance. Group names can be 1 to 90 characters and cannot be changed later, so decide on the convention first. Tags describe ownership for cost reports and audits.
export RG1="rg-payments-dev-mumbai"export RG2="rg-inventory-dev-mumbai" az group create \ --name $RG1 \ --location centralindia \ --tags env=dev owner=rahul team=payments az group create \ --name $RG2 \ --location centralindia \ --tags env=dev owner=priya team=inventoryHow to Create a Resource Inside a Resource Group
Storage account names are globally unique, so change the suffix if yours is taken.
export SA="stpaymentsdevrahul2026" az storage account create \ --name $SA \ --resource-group $RG1 \ --location centralindia \ --sku Standard_LRSHow to Confirm That Tags Do Not Inherit
The Resource Group has tags, but the storage account inside it does not.
az group show --name $RG1 --query tagsaz storage account show --name $SA --resource-group $RG1 --query tagsHow to Show That a Group's Region Is Only Metadata
The group's region decides where its deployment metadata lives, but resources inside it can be created in other regions.
az storage account create \ --name stpaymentsdevsouth2026 \ --resource-group $RG1 \ --location southindia \ --sku Standard_LRS az resource list \ --resource-group $RG1 \ --query "[].[name, location]" \ --output tableHow to List Everything Inside a Resource Group
This is the fastest answer to "what actually lives in here" before you delete anything.
az group list --query "[?tags.env=='dev'].name" --output tsv az resource list --resource-group $RG1 --output tableHow to See Inherited Role Assignments
Grant yourself the Reader role on the group, then check the role assignments that apply to the storage account. The assignment shows up there even though it was never made on the account itself.
ME=$(az ad signed-in-user show --query id --output tsv)RG1_ID=$(az group show --name $RG1 --query id --output tsv)SA_ID=$(az storage account show --name $SA --resource-group $RG1 --query id --output tsv) az role assignment create \ --assignee-object-id $ME \ --assignee-principal-type User \ --role Reader \ --scope $RG1_ID az role assignment list \ --scope $SA_ID \ --include-inherited \ --query "[?roleDefinitionName=='Reader'].[roleDefinitionName, scope]" \ --output tableHow to Move a Resource to Another Resource Group
Moving changes the resource's ID, and with it the group it inherits roles, policy, and locks from. The name and region stay the same.
az resource move \ --destination-group $RG2 \ --ids $SA_ID az resource list --resource-group $RG2 --output tableHow to Protect a Resource Group With a Lock
A CanNotDelete lock blocks deletion of the group and everything inside it, even for an Owner, until the lock is removed.
az lock create \ --name no-delete \ --lock-type CanNotDelete \ --resource-group $RG1 # Expected: fails with a ScopeLocked erroraz group delete --name $RG1 --yesHow to Clean Up
Remove the lock first, then delete both groups.
az lock delete --name no-delete --resource-group $RG1 az group delete --name $RG1 --yes --no-waitaz group delete --name $RG2 --yes --no-waitProduction Best Practices & Common Pitfalls
Common MistakePutting every resource in the company into one Resource Group called something generic like
rg-main. You cannot give each team separate access or safely delete one project's resources without risking another's. Use one Resource Group per application and environment.
TipAgree on a naming convention before the first real group exists, not after you have fifty inconsistent ones. A pattern like
rg-payments-prod-mumbaimakes each group's purpose obvious at a glance.
SecurityPut
CanNotDeletelocks on production Resource Groups. A lock stops the most expensive mistake, an accidentalaz group delete, because the command fails until someone removes the lock on purpose.
- Group by lifecycle, not by resource type. A VM, its NIC, and its disk that are deleted together belong in one group, so do not create an "all VMs" group and an "all disks" group.
- Remember that the group's region is metadata. If that region has an outage, you may be unable to create, update, or delete resources in the group, even though running resources keep working.
- Add an Azure Policy to inherit tags. Without one, resources lose the owner and environment tags you set on the group, and cost reports cannot group by them.
- Check what a move changes. A moved resource stops inheriting roles and policy from the old group and starts inheriting from the new one.
- Assign access at the narrowest useful level. Give teams roles on their own Resource Groups instead of the whole subscription, since higher grants cannot be undone lower down.
Quick Reference & Troubleshooting Commands
| Command | Description |
|---|---|
az group create --tags |
Create a tagged Resource Group |
az group list --query "[?tags.env=='dev']" |
Find groups by tag |
az resource list --resource-group NAME |
List every resource inside a group |
az resource move --destination-group NAME --ids ID |
Move a resource to another group |
az lock create --lock-type CanNotDelete |
Block accidental deletion |
az role assignment list --scope ID --include-inherited |
Show inherited role assignments |
az account management-group list |
List management groups you can see |