Locks & Tags
CanNotDelete · ReadOnly · inheritance · tags · Merge vs Replace · tag policies
By the tools4free.dev team · Last reviewed November 13, 2026
Practice questions for this topic →
Resource locks
| Lock level | Effect |
|---|---|
Delete (CanNotDelete) | Authorized users can read and modify the resource, but not delete it |
Read-only (ReadOnly) | Similar to restricting everyone to the Reader role |
- Locks apply to subscriptions, resource groups and resources, and override any user permissions. Management groups can't be locked.
- Inheritance: children inherit a parent's lock, including resources added later. The most restrictive lock wins.
- A Delete lock on any resource in a resource group blocks deleting the whole group. There is no partial delete.
- Locks apply to the control plane (management.azure.com), not the data plane. A ReadOnly lock on a SQL server still allows database data changes, and locks on a storage account don't protect blob or file data reached through data-plane calls.
- You need
Microsoft.Authorization/*orMicrosoft.Authorization/locks/*to create or delete locks. Owner and User Access Administrator have it. - Portal blade: Resource locks on a subscription, Locks on a resource group or resource. Add: Locks › Add › name, lock type, notes.
- Locks don't block subscription cancellation.
- Managed applications (such as Databricks) lock their infrastructure resource group. Delete the service instead.
- In Bicep or ARM use
Microsoft.Authorization/lockswith level CanNotDelete or ReadOnly. Setscopeto lock a child resource.
Side effects of locks
| Lock | Where | What breaks |
|---|---|---|
| ReadOnly | Storage account | List Keys (a POST) is blocked, and blob container creation is blocked |
| ReadOnly | Resource group with a VM | Start and restart are blocked |
| ReadOnly | Resource group with an App Service plan | Scale up and scale out are blocked |
| ReadOnly | Resource group with an Automation account | Starting a runbook is blocked |
| ReadOnly | Network security group | Flow log creation is blocked |
| ReadOnly | Subscription | Azure Advisor can't store results |
| CanNotDelete | Resource group | Automatic deletion of deployment history is blocked (deployments fail at 800 history entries), RBAC assignments can't be deleted, and Azure Backup restore point cleanup can break |
Locks and moves: a ReadOnly lock on the source or destination resource group or subscription blocks a move. Remove it first.
Lock commands
| Task | Azure CLI | PowerShell |
|---|---|---|
| Lock a resource group | az lock create --name LockGroup --lock-type CanNotDelete --resource-group exampleresourcegroup | New-AzResourceLock -LockName LockGroup -LockLevel CanNotDelete -ResourceGroupName exampleresourcegroup |
| Lock a resource | az lock create --name LockSite --lock-type CanNotDelete --resource-group <rg> --resource-name <n> --resource-type Microsoft.Web/sites | New-AzResourceLock -LockLevel CanNotDelete -LockName LockSite -ResourceName <n> -ResourceType Microsoft.Web/sites -ResourceGroupName <rg> |
| List locks | az lock list | Get-AzResourceLock |
| Delete a lock | az lock delete --ids <lockId> | Remove-AzResourceLock -LockId <id> |
Tags
- Tags are key-value pairs on resources, resource groups and subscriptions. Not management groups. Classic resources don't support tags.
- No inheritance: resources don't inherit tags from a resource group or subscription. Use Azure Policy (Modify) to copy them.
- Tag names are case-insensitive for operations. Tag values are case-sensitive.
- Tags are plain text. They show up in cost reports, deployment history, exported templates and logs, so don't store secrets.
- Write access to
Microsoft.Resources/tags(the Tag Contributor role) lets you tag without access to the resource itself. Tag Contributor can't tag resources or resource groups in the portal, but can tag subscriptions in the portal and everything through PowerShell or REST. Contributor works too, because it has write access to the resource. - The
cm-resource-parenttag holds a resource ID and groups costs by a parent resource in Cost Management. - Not every resource type supports tags. Check Microsoft's tag support list.
| Limit | Value |
|---|---|
| Tag name-value pairs per resource, resource group and subscription | 50 |
| Services limited to 15 tags | Automation, CDN, public and private DNS, Log Analytics saved search |
| Tag name length | 512 characters (128 for storage accounts) |
| Tag value length | 256 characters |
| Characters not allowed in names | < > % & \ ? / |
Tag commands
| Task | Azure CLI | PowerShell |
|---|---|---|
| Set tags, replacing the whole set | az tag create --resource-id $resource --tags Dept=Finance Status=Normal | New-AzTag -ResourceId $resource.id -Tag $tags |
| Merge: add new names and update existing values, keep the rest | az tag update --resource-id <id> --operation Merge --tags key1=value1 | Update-AzTag -ResourceId <id> -Tag $tags -Operation Merge |
| Replace the whole set | az tag update --resource-id <id> --operation Replace --tags key1=value1 | Update-AzTag -ResourceId <id> -Tag $tags -Operation Replace |
| Delete only the named tags | az tag update --resource-id $resource --operation Delete --tags Project=ECommerce Team=Web | Update-AzTag -ResourceId $resource.id -Tag $removeTags -Operation Delete |
| Remove all tags | az tag delete --resource-id $resource | Remove-AzTag -ResourceId <id> |
| List tags | az tag list --resource-id $resource | Get-AzTag -ResourceId $resource.id |
| Find by tag | az resource list --tag CostCenter=00123 --query [].name | (Get-AzResource -Tag @{ "CostCenter"="00123"}).Name |
- Merge with an existing tag name replaces its value, because a name has one value.
az tag delete --resource-iddeletes the entire tag set, even if--nameis also given.az tag delete --name MyTag(no resource ID) deletes a predefined tag name that isn't associated with a resource.- Quote names or values that contain spaces in the CLI.
- Azure CLI 2.10.0 or later is needed for
az tag createandaz tag update. The Az.Resources module 1.12.0 or later is needed forNew-AzTagandUpdate-AzTag.
Built-in tag policies
| Policy type | Effect | Existing resources |
|---|---|---|
| Require a tag (and its value) | Deny | Enforces the tag (Deny) |
| Append a tag and its value | Append | Not changed until they are changed |
| Add a tag, Add or replace a tag, Inherit a tag | Modify | Fixed by a remediation task |
- "Add a tag" and "Inherit a tag ... if missing" add the tag only when it is missing. "Add or replace" and "Inherit a tag from the resource group" add or replace the value.
- "Require a tag on resources" doesn't apply to resource groups. Use "Require a tag on resource groups" for those.
Exam Tips
Tick each tip once you can answer it without looking.
“Prevent accidental deletion but keep editing allowed” → CanNotDelete lock. Trap: ReadOnly also blocks changes.
“Owner can't delete a resource group that has a lock” → A lock overrides permissions: remove the lock first. Trap: a higher role doesn't bypass a lock.
“Delete lock on one VM, then delete its resource group” → The whole group delete is blocked. Trap: it isn't a partial delete that spares only the VM.
“ReadOnly lock on a resource group; a VM won't start” → Start and restart are blocked by the lock: remove it. Trap: a VM extension problem.
“ReadOnly lock on a storage account; listing keys fails” → List Keys is a POST, which the lock blocks. Trap: a firewall problem.
“ReadOnly lock on a subscription; Advisor shows errors” → Advisor can't store its results under the lock. Trap: an Advisor outage.
“Lock a management group” → Not supported. Trap: the portal Locks blade.
“Who can create or delete locks?” → Owner or User Access Administrator (Microsoft.Authorization/locks/*). Trap: Contributor isn't named on the page as having it.
“Storage account has a lock, but blobs were still deleted” → Locks cover the control plane, not data-plane calls. Trap: assuming the data is protected.
“Move resources out of a resource group with a ReadOnly lock” → Blocked: remove the lock first. Trap: a ReadOnly lock on the source or destination resource group or subscription blocks a move.
“VMs in a group must carry the group's CostCenter tag, including existing ones” → Azure Policy Modify (Inherit a tag) plus a remediation task. Trap: tags aren't inherited automatically.
“Tag any resource without access to the resource” → Tag Contributor role. Trap: Contributor also works, but only because it has write access to the resource itself.
“Tag limit per resource” → 50 name-value pairs. Trap: 15 applies only to a few services.
“Tags Env and ENV” → Names are case-insensitive; values are case-sensitive. Trap: treating them as two different tags.
“Tag a management group” → Not possible. Trap: applying the tag at the root management group.
“Store a password in a tag” → Don't: tags are plain text and appear in cost reports and templates. Trap: tags are encrypted.
“Add a tag and keep the existing ones” → az tag update --operation Merge. Trap: az tag create and New-AzTag replace the whole set.
“Remove only two tags and keep the rest” → az tag update --operation Delete with those tags. Trap: az tag delete --resource-id removes all tags.
“Require a tag on every new resource” → Require a tag on resources (Deny). Trap: it doesn't apply to resource groups; use the resource group version.
Sources
- Lock your Azure resources
- Use tags to organize resources
- Apply tags with Azure CLI
- Apply tags with Azure PowerShell
- Tag policies
- Move resources to a new resource group or subscription
- az tag reference
Checked against Microsoft Learn on November 13, 2026.