Accidental deletions and unauthorized configuration changes are among the most common causes of downtime in cloud environments. In enterprise Azure deployments, even a small mistake—like deleting a production resource group—can lead to costly outages.
That’s where Azure Locks come in.
Using the Azure CLI az lock command, administrators can enforce protection at the subscription, resource group, or resource level. Locks prevent accidental deletion or modification, helping teams maintain security, compliance, and operational stability.
In this complete guide, you’ll learn how to:
- Create subscription-level and resource group-level locks
- Delete Azure locks safely
- List and inspect active locks
- Use
az lock showfor auditing - Understand real-world use cases for Azure governance
Let’s get started.
What Are Azure Locks?
Azure Locks are a feature of Microsoft Azure that prevent accidental or unauthorized changes to critical resources.
There are two main lock types:
- ReadOnly – Prevents modifications and deletions
- CanNotDelete – Prevents deletion but allows modifications
Locks can be applied at:
- Subscription level
- Resource group level
- Individual resource level
When applied at a higher scope (like subscription), the lock is inherited by all underlying resources.
Prerequisites
Before using Azure Locks via CLI:
- Install Azure CLI
- Log in:
az login
- Ensure you have sufficient permissions (Owner or User Access Administrator role)
Use Case 1: Create a Read-Only Subscription-Level Lock
Command
az lock create --name lock_name --lock-type ReadOnly
Why Use It?
A subscription-level lock is ideal for:
- Production environments
- Compliance-controlled workloads
- Enterprise infrastructure governance
This ensures no one can modify or delete critical resources across the entire subscription.
Parameter Breakdown
--name lock_name
Assigns a name to the lock. Use descriptive names likeprod-readonly-lock.--lock-type ReadOnly
Makes all resources view-only. No changes allowed.
Example Output
{
"id": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/locks/{lockName}",
"level": "ReadOnly",
"name": "lock_name",
"type": "Microsoft.Authorization/locks"
}
Use Case 2: Create a Read-Only Resource Group Lock
Command
az lock create --name lock_name --resource-group group_name --lock-type ReadOnly
Why Use It?
This is useful when:
- Multiple teams manage different resource groups
- Only specific workloads need protection
- You want granular control instead of locking the entire subscription
For example, protect your production resource group without affecting development environments.
Parameters Explained
--resource-group group_name
Targets a specific resource group.--lock-type ReadOnly
Blocks modifications and deletions within that group.
Example Output
{
"id": "/subscriptions/{subscriptionId}/resourceGroups/{groupName}/providers/Microsoft.Authorization/locks/{lockName}",
"level": "ReadOnly",
"name": "lock_name",
"type": "Microsoft.Authorization/locks"
}
Use Case 3: Delete a Subscription-Level Lock
Command
az lock delete --name lock_name
When Should You Delete a Lock?
- Infrastructure migrations
- Administrative handovers
- Planned architecture changes
- Temporary protection removal
Important Consideration
Always verify the lock name before deleting. Removing the wrong lock can expose critical infrastructure.
Example Output
{
"status": "Succeeded",
"message": "Lock 'lock_name' successfully deleted."
}
Use Case 4: Delete a Resource Group Lock
Command
az lock delete --name lock_name --resource-group group_name
Why This Matters
When a project lifecycle ends or restrictions need adjustment, removing a resource group lock restores flexibility for updates or decommissioning.
Parameters
--name lock_name--resource-group group_name
Example Output
{
"status": "Succeeded",
"message": "Lock 'lock_name' on resource group 'group_name' successfully deleted."
}
Use Case 5: List All Subscription-Level Locks
Command
az lock list
Why Use It?
Perfect for:
- Auditing active protection policies
- Security reviews
- Governance compliance checks
- Troubleshooting blocked operations
Example Output
[
{
"id": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/locks/{lock1}",
"level": "ReadOnly",
"name": "lock1",
"type": "Microsoft.Authorization/locks"
}
]
This gives you full visibility into your active Azure locks.
Use Case 6: Show Details for a Specific Lock
Command
az lock show -n lock_name
Why It’s Useful
Use this command when:
- Investigating blocked operations
- Auditing configuration
- Confirming lock type and scope
- Troubleshooting resource access issues
Parameter
-n lock_name
Displays detailed information about the specified lock.
Example Output
{
"id": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/locks/{lockName}",
"level": "ReadOnly",
"name": "lock_name",
"type": "Microsoft.Authorization/locks"
}
Best Practices for Using Azure Locks
To maximize security and maintain operational flexibility:
1. Use Clear Naming Conventions
Examples:
prod-subscription-lockfinance-rg-readonlycritical-db-delete-lock
2. Avoid Overusing Subscription Locks
Locking an entire subscription can restrict legitimate administrative work.
3. Document Lock Policies
Keep track of:
- Why the lock exists
- Who approved it
- When it should be reviewed
4. Combine Locks with RBAC
Azure Locks protect against accidental changes—even from admins—but should complement Role-Based Access Control (RBAC), not replace it.
Common Errors When Using az lock
1. Insufficient Permissions
Error:
AuthorizationFailed
Solution:
Ensure you have Owner or User Access Administrator role.
2. Resource Cannot Be Modified Due to Lock
Error:
The scope is locked.
Solution:
List locks:
az lock list
Then remove the relevant lock.
Why Azure Locks Are Critical for Cloud Governance
In modern DevOps environments, automation pipelines, multiple teams, and frequent deployments increase the risk of accidental changes.
Azure Locks provide:
- Protection against accidental deletions
- Infrastructure stability
- Compliance enforcement
- Strong governance control
- Enterprise-level resource protection
They act as a safety net—even when administrators have full permissions.
Final Thoughts
The Azure CLI az lock command is a powerful governance tool for protecting cloud infrastructure. Whether you’re managing enterprise production workloads or securing a critical resource group, Azure Locks provide essential safeguards against costly mistakes.
By mastering how to create, list, show, and delete locks, you gain stronger control over your Azure environment and significantly reduce operational risk.
In production cloud environments, protection isn’t optional—it’s mandatory.
And if you'd like to go a step further in supporting us, you can treat us to a virtual coffee ☕️. Thank you for your support ❤️!
We do not support or promote any form of piracy, copyright infringement, or illegal use of software, video content, or digital resources.
Any mention of third-party sites, tools, or platforms is purely for informational purposes. It is the responsibility of each reader to comply with the laws in their country, as well as the terms of use of the services mentioned.
We strongly encourage the use of legal, open-source, or official solutions in a responsible manner.


Comments