Lock Types in Azure
Azure offers two built-in lock levels:| Lock Type | Description | Operations Allowed |
|---|---|---|
| Cannot Delete | Prevents deletion but permits all other operations (read, write, update) | Read, Write, Update |
| Read Only | Blocks create, update, and delete operations | Read only |
Cannot Delete Lock
The Cannot Delete lock (also known asCanNotDelete) ensures a resource remains in place:
- Read and write operations are fully supported.
- Any attempt to delete the resource is blocked.
Apply locks at the highest possible scope (subscription or resource group) to cover all child resources automatically.
Read Only Lock
The Read Only lock restricts a resource to read-only mode:- Only GET operations are permitted.
- All PUT, PATCH, POST, and DELETE actions are blocked.
Applying a Read Only lock will prevent even administrative updates. Always verify you won’t need to modify the resource before locking.
Managing Locks in Azure
You can manage locks in multiple ways:| Method | Command / Action |
|---|---|
| Azure Portal | Navigate to Resource > Locks and Add new lock |
| Azure CLI | az lock create / az lock delete |
| Azure PowerShell | New-AzResourceLock / Remove-AzResourceLock |
| ARM Template | Use "Microsoft.Authorization/locks" under resources in JSON |
Sample ARM Template Snippet
Integration with RBAC and Governance
Resource locks complement Azure Role-Based Access Control (RBAC) and policies:- RBAC defines who can perform operations.
- Locks define which operations are blocked, regardless of RBAC rights.
- Combine both for granular governance across subscriptions.
Key Points
- Locks are inherited by child resources.
- You need Microsoft.Authorization/locks/delete permission to remove a lock.
- Policy-based locks can enforce organizational standards at scale.
Exam and Real-World Scenarios
For the AZ-400 certification and practical deployments, be prepared to:- Differentiate between Cannot Delete and Read Only locks.
- Choose the appropriate lock type based on business requirements.
- Explain how locks interact with RBAC roles and Azure Policy.