Azure Policy, Resource Locks and Standardized Deployments: Governance Guardrails for Every Subscription
RBAC vs Policy
| Azure RBAC | Azure Policy | |
|---|---|---|
| Question | Who can do an action? | What is allowed on resources? |
| Example | Asha can create VMs | VMs may only be created in India regions |
| Applies to | People and identities | Resource properties, even for Owners |
Azure Policy Concepts
| Term | Meaning |
|---|---|
| Policy definition | A rule in JSON: a condition (if) and an effect (then) |
| Initiative (policy set) | A group of definitions with one goal (for example 'ISO 27001' or 'tagging standard') |
| Assignment | Applies a definition or initiative to a scope (management group, subscription, resource group) with parameters and exclusions |
| Compliance | Dashboard showing which resources follow the rules |
| Remediation task | Fix existing non-compliant resources (for Modify and DeployIfNotExists) |
Effects
| Effect | What happens |
|---|---|
| Deny | Blocks the request that would create or change a non-compliant resource |
| Audit | Allows it, but records it as non-compliant |
| Modify | Adds or changes properties such as tags automatically |
| Append | Adds fields during creation |
| DeployIfNotExists | Deploys a related resource if missing (for example diagnostic settings) |
| AuditIfNotExists | Reports missing related resources |
| Disabled | Turn the policy off for testing |
A Policy: Allowed Locations
json
{
"properties": {
"displayName": "Allowed locations for resources",
"mode": "Indexed",
"parameters": {"allowedLocations": {"type": "Array"}},
"policyRule": {
"if": {"not": {"field": "location", "in": "[parameters('allowedLocations')]"}},
"then": {"effect": "deny"}
}
}
}
bash
# Assign the built-in "Allowed locations" policy to a subscription
az policy definition list --query "[?displayName=='Allowed locations'].name" -o tsv
az policy assignment create --name allowed-locations --display-name "Allowed locations" \
--policy $(az policy definition list --query "[?displayName=='Allowed locations'].name | [0]" -o tsv) \
--scope /subscriptions/<sub-id> --params '{"listOfAllowedLocations":{"value":["centralindia","southindia"]}}'
az policy state summarize --query "results.nonCompliantResources"
Good Policy Ideas
- Require tags such as
ownerandenv, or inherit tags from the resource group with Modify - Allowed regions and allowed VM sizes
- Deny public IP on network interfaces
- Require HTTPS on storage accounts and web apps
- DeployIfNotExists: send diagnostic logs to a Log Analytics workspace
- Use built-in initiatives such as Microsoft cloud security benchmark
Roll out safely Assign with Audit first, read compliance results, fix problems, then switch to Deny. Use exclusions for special cases.
Resource Locks
| Lock | Effect |
|---|---|
| CanNotDelete | Users can read and change but not delete |
| ReadOnly | Users can only read (like Reader for everyone, including Owners) |
bash
az lock create --name keep-db --lock-type CanNotDelete --resource-group rg-shop-data-prod
az lock list --resource-group rg-shop-data-prod -o table
- Locks apply to everyone, even Owners, until the lock is removed
- Locks inherit to child resources
- A ReadOnly lock can break things that need to write (for example a storage account listing keys, or an App Service plan scaling)
Standardized Deployments
- Template specs: store ARM or Bicep templates in Azure with versions and RBAC so teams reuse approved patterns
- Deployment stacks: manage a group of resources as one unit and prevent unmanaged changes or deletes
- Azure Blueprints (older packaged environment definitions) is being retired in favor of template specs, deployment stacks and Azure Policy. Check current status before using it for new work
Practice
- Assign the Allowed locations policy in Audit mode, then Deny
- Create a policy that requires an
ownertag - Add a CanNotDelete lock to a resource group and try to delete it
- Explain why a ReadOnly lock may break a service
Conclusion
Azure Policy enforces standards on resources with effects like Deny, Audit, Modify and DeployIfNotExists. Use initiatives, start with Audit, add resource locks for critical items and reuse approved templates.
Quick Summary: RBAC vs Policy; concepts; effects; example; ideas; locks; deployments.

