Azure Policy, Locks, Tags and Management Groups: Enforce Rules and Organize Resources
Management Groups
- A container above subscriptions. Policy and RBAC assigned here inherit to all subscriptions below
- Up to six levels deep (not counting subscriptions). Every tenant has a root management group
- Use to apply rules to many subscriptions at once
bash
az account management-group create --name mg-prod --display-name "Production"
az account management-group subscription add --name mg-prod --subscription <sub-id>
az account management-group list -o table
Azure Policy
| Concept | Meaning |
|---|---|
| Definition | The rule (condition and effect) |
| Initiative | A group of definitions |
| Assignment | Applies a definition or initiative to a scope |
| Compliance | Report of resources that meet or break the rule |
| Remediation | Fixes existing resources for modify and deployIfNotExists |
| Effect | Behavior |
|---|---|
| Deny | Blocks creation or change |
| Audit | Allows but flags |
| Append / Modify | Adds or changes properties such as tags |
| DeployIfNotExists | Deploys a related resource if missing |
| Disabled | Off |
bash
# Assign a built-in policy: allowed locations
az policy assignment create --name allowed-locations --display-name "Allowed locations" \
--policy $(az policy definition list --query "[?displayName=='Allowed locations'].name | [0]" -o tsv) \
--params '{"listOfAllowedLocations":{"value":["centralindia","southindia"]}}' --scope /subscriptions/<sub-id>
az policy state summarize --resource-group rg-demo
az policy remediation create --name fix-tags --policy-assignment <assignment-id>
Policy is not RBAC RBAC controls who can act. Policy controls what is allowed, even for Owners. Policy evaluates when resources are created or updated, and on a regular schedule.
Resource Locks
| Lock | Effect |
|---|---|
| CanNotDelete | Can read and change, cannot delete |
| ReadOnly | Can only read. Blocks changes (can have side effects, such as listing keys being blocked) |
bash
az lock create --name keep-rg --lock-type CanNotDelete --resource-group rg-prod
az lock list -o table
az lock delete --name keep-rg --resource-group rg-prod
- Locks apply to everyone, including Owners. Remove the lock to delete
- Locks inherit down the scope
Tags
bash
az tag create --resource-id /subscriptions/<sub-id>/resourceGroups/rg-demo --tags CostCenter=1001 Environment=Dev
az resource list --tag Environment=Dev -o table
az group update -n rg-demo --set tags.Owner=Asha
- Up to 50 tag name/value pairs per resource
- Tags help cost reports, automation and ownership
- Use a policy to require or inherit tags
Moving Resources
bash
az resource move --destination-group rg-new --ids $(az resource show -g rg-old -n myvm --resource-type Microsoft.Compute/virtualMachines --query id -o tsv)
az resource move --destination-group rg-new --destination-subscription-id <other-sub-id> --ids <resource-id>
- Not every resource type can move. Validate first (portal does it)
- Resources keep their region. The resource ID changes
- Moving between subscriptions needs permissions on both sides and the same tenant
Azure Resource Graph
kql
resources
| where type == "microsoft.compute/virtualmachines"
| summarize count() by location
resources
| where isnull(tags.Owner)
| project name, type, resourceGroup
Practice
- Assign an Allowed locations policy and try to create a resource elsewhere
- Add a CanNotDelete lock and try to delete the group
- Find resources without an Owner tag using Resource Graph
- Move a storage account to another resource group
Conclusion
Use management groups to apply rules at scale, Azure Policy to enforce standards, locks to prevent accidents, tags to organize and Resource Graph to query everything quickly.
Quick Summary: management groups; Policy; locks; tags; moving; Resource Graph.

