Your profile

One profile for every MSDEVBUILD site. Only you can see it, and the site owner if you write in.

Lesson 6 of 47
❮Prev Next❯

Implement and Manage Azure Policy

Module 1: Identity & Governance ⏱ 12 min read Updated

Your note

My notes for this lesson

Select any text in the lesson to highlight it or add a note. Saved in this browser.

    No highlights yet. Select a sentence in the lesson, then pick a colour or add a note.

    All my bookmarks and notes

    Reading settings

    For every lesson, saved in this browser.

    Text size
    Line spacing
    Font

    With IaaS you rent the virtual machine. Microsoft looks after the building, power and hardware; you patch the operating system.

    30-second answer

    Azure Policy checks resources against rules and applies an effect. A policy definition holds the rule; an initiative groups several; an assignment applies one to a scope (management group, subscription or resource group), with optional exclusions and parameters. Common effects are Deny (block the request), Audit (allow but mark non-compliant), Append, Modify (change properties such as tags during deployment) and DeployIfNotExists (deploy a related resource). Modify and DeployIfNotExists need a managed identity, and a remediation task fixes resources that existed before the assignment. Enforcement mode: Disabled lets you test without blocking. Compliance shows in Policy → Compliance.

    Simulate it » No Azure account needed

    Exam objective: 1.3.1 Implement and manage Azure Policy. (Skills measured as of April 17, 2026)

    Simulations

    Feel it before you read it. No account needed, nothing leaves this page.

    Azure portal: Assign a Modify policy and remediate existing resources Assign a Modify policy with a managed identity and remediate.
    </> Embed

    Embed this simulation

    Free for trainers, teachers and bloggers. Paste this into your page:

    Loading the portal…

    Search for <strong>Policy</strong>.

    👆 Click the glowing item in the portal to continue

    Read the steps as text
    1. Search for Policy.
    2. Type policy in the search bar and pick Policy under Services.
    3. Under Authoring → Definitions, find Inherit a tag from the resource group if missing. Its effect is Modify: it adds the tag rather than refusing the deployment.
    4. Scope can be a management group, subscription or resource group. Policy enforcement: Disabled (DoNotEnforce) lets you test compliance without changing anything.
    5. Tell it which tag to copy: costcenter.
    6. A Modify policy needs a managed identity with rights to change resources. Ticking Create a remediation task fixes resources that already exist.
    7. Create. CLI: az policy assignment create -n inherit-costcenter --policy ea3f2387-… -g rg-finance --params tagName=costcenter --mi-system-assigned --location westeurope.
    8. New evaluations can take up to about 30 minutes. Existing resources show Non-compliant until remediation has run.
    9. The remediation task tagged all three. CLI: az policy remediation create -n fix-cc --policy-assignment inherit-costcenter -g rg-finance. Deny and Audit policies can't be remediated; only Modify and DeployIfNotExists.

    🧪 Simulation for learning. Screens are simplified versions of the Azure portal; names, prices and IDs are examples. Nothing here touches real Azure.

    😟 THE PROBLEM

    Half the resources have no cost center tag and some sit in the wrong region.

    😊 THE SOLUTION

    Deny the wrong region, Modify in the missing tag, and remediate the rest.

    • Resources in any region✓ Allowed locations (Deny)
    • Missing tags✓ Inherit a tag (Modify)
    • Old resources still wrong✓ Remediation tasks
    🛠️ Solved with: Azure Policy

    Start with a question

    How does a building inspector keep every new house safe without visiting every site every day?

    A council publishes building rules: no houses on the flood plain, every house needs a smoke alarm. Some rules stop the build before it starts (planning permission refused). Some just get noted on an inspection report. And some the council fixes for you, like fitting the missing smoke alarm and sending the bill.

    Azure Policy is that rulebook. Deny refuses the build, Audit writes it on the report, and Modify fits the smoke alarm for you.

    Explain it like I’m 10

    The technical explanation

    The pieces

    • Definition: the rule (if a condition, then an effect). Hundreds are built-in; you can write custom ones in JSON.
    • Initiative (policy set): several definitions grouped, such as a security baseline.
    • Assignment: a definition or initiative applied at a scope (management group, subscription, resource group) with parameters, exclusions, a non-compliance message and an enforcement mode.
    • Exemption: excludes one resource or scope, with a reason (waiver or mitigated) and an optional expiry.

    Policies assigned higher up apply to everything below. The person deploying doesn’t matter: an Owner is stopped by Deny just like anyone else.

    Effects

    EffectWhenResultNeeds identity?
    DenyCreate or updateRequest refused with RequestDisallowedByPolicyNo
    AuditCreate, update and evaluationAllowed, marked Non-compliantNo
    AppendCreate or updateAdds fields, such as IP rulesNo
    ModifyCreate or update, and remediationAdds, replaces or removes tags and some propertiesYes
    AuditIfNotExistsAfter deploymentFlags if a related resource (like an extension) is missingNo
    DeployIfNotExistsAfter deployment, and remediationDeploys the missing related resource, such as diagnostic settingsYes
    DisabledNeverTurns the rule offNo

    Assign a policy

    Portal: Policy → Definitions → pick one → Assign policy. Tabs: Basics (scope, exclusions, assignment name, Policy enforcement), Parameters, Remediation (create a remediation task, managed identity type and location), Non-compliance messages, Review + create.

    # Deny anything outside two regions, at a management group
    az policy assignment create -n eu-only \
      --policy e56962a6-4747-49cd-b67b-bf8b01975c4c \
      --scope /providers/Microsoft.Management/managementGroups/mg-contoso \
      --params '{ "listOfAllowedLocations": { "value": ["westeurope","northeurope"] } }'
    
    # Modify: copy the costcenter tag from the resource group, with a managed identity
    az policy assignment create -n inherit-costcenter \
      --policy ea3f2387-9b95-492a-a190-fcdc54f7b070 -g rg-finance \
      --params '{ "tagName": { "value": "costcenter" } }' \
      --mi-system-assigned --location westeurope
    
    # Fix resources that already exist
    az policy remediation create -n fix-costcenter --policy-assignment inherit-costcenter -g rg-finance
    
    az policy state summarize -g rg-finance        # compliance numbers
    az policy state trigger-scan -g rg-finance     # re-evaluate now

    When you assign through the CLI, give the managed identity a role (for tags, Tag Contributor) at the scope. The portal does this for you.

    Compliance

    New assignments are evaluated within about 30 minutes; existing resources are re-checked about every 24 hours or when you trigger a scan. Policy → Compliance shows each assignment’s percentage and the non-compliant resources with the reason.

    1. 1 Deny

      A storage account in East US is refused at deployment.

    2. 2 Audit

      A VM without managed disks is created but listed as non-compliant.

    3. 3 Modify

      A new disk gets costcenter=FIN-042 copied from its resource group.

    4. 4 Remediate

      A remediation task tags the 40 disks that existed before.

    One rule, three effects
    Architect level Policy and resource groups

    Most built-in resource policies use mode Indexed, which evaluates resources that support tags and location, not resource groups themselves. That’s why there are separate definitions like Require a tag on resource groups. A resource group’s tags are also not inherited by its resources; Inherit a tag from the resource group (Modify) is the built-in fix. Allowed locations doesn’t apply to resource groups either; use Allowed locations for resource groups if the group’s metadata location matters.

    Real-world business scenario

    Logistics

    Tailwind Traders (fictional)

    The problem
    Tailwind found storage accounts in four regions it had never approved and could only attribute 60% of its Azure spend to a department.
    What they used
    An initiative at the root management group with Allowed locations (Deny, West Europe and North Europe), Inherit a tag from the resource group if missing for costcenter (Modify, system-assigned identity) and Require a tag on resource groups (Deny). Remediation tasks tagged the existing estate.
    Why that choice
    Wrong-region deployments now fail immediately, every resource carries its group's cost center, and new subscriptions inherit the rules the day they're created.
    The result
    Untagged spend fell from 40% to under 3%, and no new resources appeared outside Europe.

    When to use it and when not to

    ✓ Use it when…

    • Restricting regions, SKUs or resource types across many subscriptions.
    • Adding or enforcing tags automatically.
    • Deploying required settings (diagnostics, agents) with DeployIfNotExists.

    ✕ Think twice when…

    • Deciding which people can act. Use RBAC.
    • Protecting one critical resource from deletion. Use a lock.
    • Going straight to Deny on a big estate without testing in Audit or DoNotEnforce first.

    ↔ Alternatives to consider

    • Initiatives to manage many related rules together.
    • Microsoft Defender for Cloud regulatory compliance, which is built on Policy initiatives.
    Ready for more?The full lesson adds the technical explanation, when to use it, interview questions and revision notes.

    Test yourself with exercises

    5 original practice questions in the AZ-104 style. Pick your answers, then check them. You will see why each option is right or wrong. Score 75% or more and this topic is marked complete.

    Question 1

    Question 1 of 5

    You must prevent users from creating resources outside the West Europe and North Europe regions in all subscriptions under a management group. What should you do?

    Question 2

    Question 2 of 5

    You assign a policy that uses the Modify effect to add a missing tag to resources. Existing resources remain non-compliant. What should you do?

    Question 3

    Question 3 of 5

    You plan to assign a policy definition that uses the DeployIfNotExists effect by using Azure CLI. What must the assignment include?

    Question 4

    Question 4 of 5 · Select 2

    You need to evaluate how many existing resources would violate a new policy before the policy blocks any deployment. Which two approaches meet the requirement? Each correct answer presents a complete solution.

    Question 5

    Question 5 of 5

    You need to apply 12 related policy definitions to several subscriptions and manage them as a single unit with one compliance score. What should you create?

    Interview preparation

    Say your answer out loud first, then open the model answer. Interviewers care more about your reasoning than the exact words.

    Beginner What's the difference between Azure Policy and RBAC?

    Model answer

    RBAC decides who can do things. Policy decides what's allowed to exist, whoever does it. An Owner can still be stopped by an Allowed locations policy, because policy is about the resource, not the person.

    Intermediate Deny or Audit for a new tagging rule?

    Model answer

    I'd usually start with Audit, or the assignment in DoNotEnforce mode, to see how many resources would fail without breaking anyone's deployments. Then move to Modify to add the tag automatically, or Deny if teams must supply it themselves.

    Experienced developer Why does a Modify or DeployIfNotExists assignment need a managed identity?

    Model answer

    Because Policy itself makes the change, not the user. The assignment's managed identity needs a role such as Tag Contributor or Contributor on the scope. The portal creates and grants it for you on the Remediation tab; with the CLI you add --mi-system-assigned and --location, then assign the role.

    Scenario You assigned Inherit a tag from the resource group, but old resources still don't have the tag. What now?

    Model answer

    Modify only acts on create and update requests. For resources that already existed I'd create a remediation task for the assignment, either from Policy, Remediation, or with az policy remediation create. It uses the managed identity to add the tag to every non-compliant resource.

    Quick revision

    Key points

    • Definition (rule) → initiative (group) → assignment (scope + parameters + exclusions).
    • Deny blocks; Audit flags; Modify and Append change the request; DeployIfNotExists deploys something related.
    • Modify and DeployIfNotExists need a managed identity with the right role.
    • Remediation tasks fix existing resources. Deny and Audit can't be remediated.
    • Enforcement mode Disabled (DoNotEnforce) evaluates without blocking. Exemptions exclude specific resources.

    Important terminology

    Policy definition
    A JSON rule with a condition and an effect, such as Allowed locations or Require a tag on resources.
    Initiative
    A set of policy definitions assigned together, for example a regulatory baseline.
    Assignment
    A definition or initiative applied to a scope with parameter values, exclusions and an enforcement mode.
    Effect
    What happens when a resource matches the rule - Deny, Audit, Append, Modify, DeployIfNotExists, AuditIfNotExists or Disabled.
    Remediation task
    A job that applies a Modify or DeployIfNotExists policy to resources that already exist.
    Exemption
    A record that excludes a resource or scope from an assignment, with a reason and optional expiry.
    Enforcement mode
    Enabled (Default) applies the effect; Disabled (DoNotEnforce) only evaluates compliance.

    Common mistakes

    • Expecting a new Deny policy to remove or fix resources that already exist. It only blocks new requests; old ones show non-compliant.
    • Forgetting that resource groups themselves aren't checked by many resource-level policies like Require a tag on resources.

    Exam tips

    • "Prevent resources outside West Europe" = Allowed locations (Deny).
    • "Add the tag automatically, including to existing resources" = Modify policy + remediation task.
    • "Apply several policies as one unit" = an initiative.

    Five quick revision questions

    1. 1.Which effects support remediation tasks?Show

      Modify and DeployIfNotExists.

    2. 2.What does Audit do to a non-compliant resource?Show

      Lets it be created or changed and marks it non-compliant.

    3. 3.Which enforcement mode tests a policy without blocking?Show

      Disabled (DoNotEnforce).

    4. 4.What's a group of policy definitions called?Show

      An initiative (policy set definition).

    5. 5.Which CLI command starts a remediation?Show

      az policy remediation create --name ... --policy-assignment ...

    Official references

    Finished this lesson? Tick it off. Your progress is saved in this browser.

    Next up: Resource Locks and Tags for Administrators

    Studying with a friend? Send them this lesson

    It's free and needs no sign-up. Their progress saves in their own browser.

    Lesson done? Make it stick with a quick gameSort It, Match the Pairs, Lightning Round and Who Am I? Earn XP and badges. Play ❯

    Install MSDEVBUILD Azure

    Free · no account · works offline

    Save the whole course for offline ›

    Hi, I’m your Nimbus

    Your study buddy. Pick what we do next.

    MSDEVBUILD · Multi-Stack Dev Build

    Sign in to MSDEVBUILD

    One account for Azure certifications and the blog: sign in here and you are signed in on both. Your XP, streak, practice deck and certificate stay in sync on every device. Optional: everything works without an account.