Azure Policy & Compliance
Azure Policy effects · assignments and initiatives · remediation · exemptions · resource locks · Defender for Cloud standards and recommendations · infrastructure as code
By the tools4free.dev team · Last reviewed November 13, 2026
Practice questions for this topic →
Azure Policy definitions and effects
A policy definition holds the rule and a single effect. Several definitions are grouped into an initiative (also called a policySet). Policy ensures resource state is compliant with the rules without concern for who made the change or who has permission to make it. Azure RBAC manages what users can do at different scopes.
| Effect | What it does | Watch for |
|---|---|---|
audit / auditIfNotExists | Reports non-compliance; changes nothing. | Microsoft recommends starting with these before an enforcement effect. |
deny | Blocks the create or update. | Evaluated before audit to prevent double logging. |
modify | Adds, updates or removes properties or tags on a subscription or resource during create or update. | Needs a managed identity to remediate. Only tags can be removed. It does not change existing resources during an evaluation cycle; it marks them non-compliant. |
deployIfNotExists | Runs a template deployment when the related resource is missing or its existenceCondition is not true. | Needs a managed identity to remediate. Existing resources are marked non-compliant but not changed. Default evaluation delay is PT10M. |
disabled | Turns the policy rule off. | Checked first, before the rule is evaluated. |
Order of evaluation: disabled, then append and modify, then deny, audit, manual, auditIfNotExists, and denyAction last.
- Layering: each assignment is evaluated on its own. The net result of overlapping policies is cumulative most restrictive. If two assignments both deny, the resource is blocked.
- Mode:
allevaluates resource groups, subscriptions and all resource types.indexedevaluates only types that support tags and location. Useindexedfor policies that enforce tags or locations. - Resource provider modes:
Microsoft.Kubernetes.Data(pods, containers, ingresses) andMicrosoft.KeyVault.Data(vaults and certificates) are examples. - Definition location must be a management group or a subscription. It decides where the definition can be assigned. A subscription location only allows assignment to resources in that subscription.
- Built-in vs custom: built-ins are provided and maintained by Microsoft; every definition you create is custom. Check the policy samples first, then map each requirement to a resource property, map the property to an alias, pick an effect and compose the definition.
- Built-in examples: Allowed Locations (Deny) restricts the locations for new resources. Add a tag to resources (Modify) applies a required tag with a default value.
- Custom policy definition versioning is in public preview, per Microsoft Learn at the time of writing.
Assignments, initiatives, remediation and exemptions
- An assignment applies a definition or initiative to a scope: management group, subscription, resource group or resource. Child resources inherit it. Always uses the latest state of the assigned definition.
- Microsoft recommends creating definitions at a management group or subscription, then assigning at the next child level, and assigning an initiative even for a single policy so policies can be added later without more assignments.
- Azure Policy is an explicit deny system. You cannot allow a resource that an assignment higher up denies by adding a more permissive assignment below it. Exclude the child scope from the higher assignment (
notScopes) and assign the more permissive definition there. - Although a policy can be assigned at a management group, only resources at the subscription or resource group level are evaluated.
| Assignment setting | Use it to |
|---|---|
notScopes (excluded scopes) | Leave a child container or resource out of evaluation. An excluded resource is different from an exempted resource. |
enforcementMode = DoNotEnforce | Evaluate without enforcing the effect and without Activity log entries. Manual remediation is still possible. Default enforces the effect. |
overrides | Change the effect of a definition (kind policyEffect) without editing the definition. Up to 10 overrides per assignment, up to 50 policyDefinitionReferenceId values per override. |
resourceSelectors | Roll out gradually by resource location, resource type or whether the resource has a location. Up to 10 per assignment. |
Remediation
- Make sure the definition lists
roleDefinitionIds(full role IDs, not role names). Built-ins already have them; custom definitions need them added underdetails. - Give the assignment a managed identity: system-assigned or user-assigned. One assignment can have only one identity, which can hold several roles.
- Grant the identity the roles. The portal does this for you; CLI, PowerShell and SDK assignments need manual role assignments or the remediation deployment fails.
- Create a remediation task. One
deployIfNotExistsormodifypolicy is remediated per task.
The assignment identity deploys or modifies resources, but it is not used to evaluate the policy rule. If roleDefinitionIds change later, the new permissions must be granted by hand, even in the portal. Contributor can trigger remediation but cannot create or update definitions and assignments; User Access Administrator is needed to grant the identity its permissions.
Exemptions
| Category | Meaning |
|---|---|
| Mitigated | The policy intent is met another way. |
| Waiver | Non-compliance is temporarily accepted. Also used to exempt a resource from some definitions of an initiative. |
- An exempt resource shows compliance state Exempt. When
expiresOnpasses, the exemption object stays for records but is no longer honored. - Creating an exemption needs
Microsoft.Authorization/policyExemptions/writeand theexempt/Actionverb on the target assignment. Resource Policy Contributor and Security Admin have read and write on exemptions. - The exemption is a child object of the resource hierarchy it exempts; if that parent is removed, the exemption is removed too.
Resource locks
A lock protects a subscription, resource group or resource from accidental deletion or modification and overrides any user permissions. Locks apply to everyone, unlike RBAC.
| Portal name | CLI / PowerShell name | Effect |
|---|---|---|
| Delete | CanNotDelete | Authorized users can read and modify, but not delete. |
| Read-only | ReadOnly | Authorized users can read only. Similar to the Reader role. |
- A lock at a parent scope is inherited by every resource below it, including resources added later. The most restrictive lock in the chain wins.
- Locks apply to the control plane only (
management.azure.com), not the data plane. A lock on a storage account does not protect its blob, queue, table or file data from data plane deletes. - A read-only lock blocks some actions that do not look like changes because they use POST: listing storage account keys, and starting or restarting a VM in a locked resource group.
- A read-only lock on a resource group blocks moving resources in or out of it. A cannot-delete lock on a resource or resource group prevents deletion of Azure RBAC assignments.
- A cannot-delete lock on the resource group created by Azure Backup Service makes backups fail, because the service cannot clean up restore points.
- A delete lock on one resource blocks deleting its resource group entirely. No partial deletion happens.
- To create or delete locks you need
Microsoft.Authorization/locks/*(orMicrosoft.Authorization/*). Owner and User Access Administrator have it. - You cannot add a lock to a management group.
Defender for Cloud: security standards and regulatory compliance
- Industry and regulatory standards and benchmarks are represented as security standards. Each has compliance controls, which are logical groups of related recommendations. They appear in the Regulatory compliance dashboard.
- Standards use Azure Policy initiatives. Defender for Cloud assesses the scope against each standard and shows resources as compliant or non-compliant.
- Enabling Defender for Cloud turns on the Microsoft Cloud Security Benchmark (MCSB) by default. Non-default standards need at least one paid plan enabled.
- Assign a standard: Regulatory compliance, then Manage compliance policies, pick the account or management group, Security policies, toggle the standard to On. Select the highest applicable scope so data aggregates for nested resources. You need Owner or Policy Contributor.
- To see compliance data you need Reader on the subscription (Security Reader does not give access to the policy compliance data). At a minimum you need Resource Policy Contributor and Security Admin.
- A control that cannot be assessed automatically shows greyed out. Manual assessments are attested with evidence. A standard with no relevant resources in the subscription is not shown at all, even when assigned.
- Assessments run about every 12 hours, so a fix shows in compliance data after the next run.
- Export: Download report gives a PDF summary; Audit reports gives Azure and Dynamics certification reports; continuous export sends data to Event Hubs or a Log Analytics workspace; workflow automation can trigger Logic Apps when an assessment changes state.
- The Defender portal shows compliance status, but configuring and assigning standards is done in the Azure portal experience.
Defender for Cloud: recommendations and security controls
| Setting on a recommendation | Result |
|---|---|
| Audit | Turns the recommendation on. |
| Disabled | Turns it off (and all its subrecommendations). |
| Deny | Prevents deployment of resources that do not comply with MCSB. |
| Enforce | Uses the DeployIfNotExist effect to remediate non-compliant resources automatically on creation. Set only from the recommendation details page. |
- Deny and Enforce apply to Azure recommendations and only a subset of them. Security Admin can update security policies; Security Reader can only view.
- Custom recommendations use KQL and need the Defender CSPM plan. Azure Policy-based custom recommendations do not need that plan. You need Security Admin to create recommendations and Owner on the subscription to create a custom standard.
- Fix appears on a recommendation only when a quick fix exists; otherwise follow the remediation steps.
- Exemptions: MCSB must be assigned on the subscription first. You need Owner or Security Admin on the scope. A mitigated exemption counts the resource as healthy; a waiver excludes it from the secure score. It can take up to 24 hours to take effect. You cannot exempt custom recommendations.
- Create exemptions in the Defender for Cloud portal: it creates the exemption in every initiative that contains the recommendation. Through the Azure Policy API you must create one per initiative. An exemption does not carry over to a newly assigned initiative.
- Governance rules assign an owner and a due date (7, 14, 30 or 90 days) to recommendations. They need the Defender CSPM plan and Contributor, Security Admin or Owner. Owner emails are sent weekly by default.
- Secure score: only built-in MCSB recommendations affect it; recommendations flagged Preview are not included. Each control is calculated every eight hours.
- Posture policies and exemptions in the Defender portal are in public preview, per Microsoft Learn at the time of writing.
Security controls by using infrastructure as code
- What-if predicts changes without changing existing resources. It works for resource group, subscription, management group and tenant deployments, for example
az deployment group what-if. - The Bicep linter checks for syntax errors and best-practice violations; one default rule is
outputs-should-not-contain-secrets(warning). - Mark secret parameters with
@secure()so Resource Manager does not log or display them. Do not output secrets: outputs are logged to the deployment history and visible to anyone with access to the deployment. - Avoid secrets when you can: many Azure resources use managed identities, so no credentials are handled in code.
- To pass a Key Vault secret as a parameter, use
getSecretand setenabledForTemplateDeploymentto true on the vault. You reference only the key vault ID, so the value is not exposed. - Microsoft Security DevOps scans connected GitHub repositories or Azure DevOps projects. Add
categories: 'IaC'(case sensitive) to scan IaC only. Results appear under Defender for Cloud, DevOps security, with no GitHub Advanced Security license needed. - Mapping IaC templates to cloud resources needs Defender CSPM, an Azure DevOps environment and the Security DevOps extension; it supports ARM, Bicep, CloudFormation and Terraform templates.
CLI and PowerShell
| Task | Azure CLI | PowerShell |
|---|---|---|
| Create a delete lock on a resource group | az lock create --name LockGroup --lock-type CanNotDelete --resource-group exampleresourcegroup | New-AzResourceLock -LockName LockGroup -LockLevel CanNotDelete -ResourceGroupName exampleresourcegroup |
| Create a policy remediation task | az policy remediation create --name myRemediation --policy-assignment '/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyAssignments/{myAssignmentId}' | - |
| Get the role ID for roleDefinitionIds | az role definition list --name "Contributor" | - |
| Preview a Bicep deployment | az deployment group what-if | - |
| Let a key vault serve template deployments | az keyvault update --name ExampleVault --enabled-for-template-deployment true | Set-AzKeyVaultAccessPolicy -VaultName ExampleVault -EnabledForTemplateDeployment |
Exam Tips
Tick each tip once you can answer it without looking.
“Block new resources outside approved regions, for everyone including admins” → Azure Policy with a deny effect (built-in Allowed Locations), assigned at a management group or subscription. Trap: RBAC controls who can act, not what a resource looks like; a lock does not check properties. Even with permission to create, Policy still blocks a non-compliant create or update.
“A deployIfNotExists or modify policy is assigned, but existing resources are still non-compliant and unchanged” → Create a remediation task; evaluation only marks existing resources non-compliant. Trap: Assuming the effect fixes old resources: it acts on create or update. One policy per remediation task.
“Remediation task fails after the assignment was made with CLI, PowerShell or an SDK” → The assignment's managed identity lacks the roles in roleDefinitionIds; grant them manually (only the portal grants them for you). Trap: Giving the roles to the person running the task. The identity deploys, and edits to roleDefinitionIds after assignment also need manual grants.
“Roll out a new deny policy and first see what it would affect” → Start with audit/auditIfNotExists, or assign with enforcementMode DoNotEnforce. Trap: DoNotEnforce skips the effect and Activity log entries but still lets you remediate manually. Do not start with an enforcement effect.
“One resource group must be left out of a subscription-level assignment” → Set notScopes on the assignment (exclusion); use an exemption when the resource must still be tracked, with a waiver or mitigated category and an expiry. Trap: An exclusion is not an exemption. You cannot allow what a parent assignment denies by adding a looser assignment below it: Policy is an explicit deny system.
“Change the effect of one policy inside an initiative without editing the definition” → An overrides entry of kind policyEffect on the assignment. Trap: Editing the shared definition affects every assignment, because assignments always use the latest definition.
“Who can create a policy exemption?” → policyExemptions/write plus the exempt/Action verb on the target assignment (Resource Policy Contributor and Security Admin have read and write). Trap: Contributor can trigger remediation but cannot create or update definitions and assignments.
“Enforce a required tag and fix existing resources too” → modify with mode indexed (needs a managed identity and a remediation task). Trap: Microsoft recommends modify over append for tags: it has more operation types and can remediate existing resources. append is for when you cannot create a managed identity. For a tag policy on a resource group, mode indexed is not required.
“A resource group holds a VM; nobody can start or restart it” → A ReadOnly lock on the resource group: starting a VM is a POST request, which the lock blocks. Trap: Looking for an RBAC or Policy cause. Also a read-only lock on a storage account blocks listing its keys.
“A delete lock is on a storage account, yet a blob was deleted” → Locks cover the control plane only; data plane operations are not blocked. Trap: Believing a lock protects blob, queue, table or file data.
“Who can create a lock, and where?” → Owner or User Access Administrator (Microsoft.Authorization/locks/*); subscription, resource group or resource, not a management group. Trap: Putting a lock on a management group is not possible.
“Add a regulatory standard in Defender for Cloud” → Regulatory compliance, then Manage compliance policies, choose the highest scope, Security policies, toggle On. Needs Owner or Policy Contributor. Standards are Azure Policy initiatives. Trap: Using the Defender portal: it shows status but standards are assigned in the Azure portal experience.
“A compliance control is greyed out, or an assigned standard is missing from the dashboard” → Greyed: cannot be assessed automatically (attest manually). Missing: the subscription has no relevant resources for that standard. Trap: Treating grey as failing; or assuming the assignment failed.
“Stop new non-compliant deployments from a Defender for Cloud recommendation” → Set the recommendation to Deny; Enforce auto-remediates with DeployIfNotExist on creation. Trap: Deny and Enforce only cover a subset of Azure recommendations; Enforce is set from the recommendation details page.
“Accept the risk on a recommendation without lowering the secure score” → A mitigated exemption counts the resource as healthy; a waiver excludes it from the score. Needs Owner or Security Admin, MCSB assigned, and up to 24 hours. Trap: Custom recommendations cannot be exempted. An Azure Policy API exemption must be repeated per initiative.
“Keep secrets out of Bicep deployments” → @secure() parameters, no secret outputs, getSecret from Key Vault with enabledForTemplateDeployment, or managed identities. Trap: Outputs are written to deployment history and readable by anyone with access to the deployment.
“Preview a Bicep deployment without changing anything” → az deployment group what-if (also subscription, management group, tenant). Trap: What-if predicts changes; it makes none. Linter checks the file itself for rule violations.
Sources
- Overview of Azure Policy
- Policy definition structure basics
- Policy definition effect basics
- deployIfNotExists effect
- modify effect
- Policy assignment structure
- Policy exemption structure
- Remediate non-compliant resources
- Tutorial: Create a custom policy definition
- Lock your Azure resources
- Regulatory compliance in Defender for Cloud
- Improve regulatory compliance
- Assign regulatory compliance standards
- Security policies in Defender for Cloud
- Create custom standards and recommendations
- Manage the Microsoft Cloud Security Benchmark
- Exempt resources from recommendations
- Remediate security recommendations
- Governance rules
- Cloud Secure Score
- Bicep what-if
- Bicep linter
- Use Bicep to manage secrets
- Key Vault secret as a Bicep parameter
- Scan for IaC misconfigurations
- Map IaC templates from code to cloud
Checked against Microsoft Learn on November 13, 2026.