Your profile

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

Lesson 7 of 47
❮Prev Next❯

Resource Locks and Tags for Administrators

Module 1: Identity & Governance ⏱ 10 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

    A resource lock stops changes for everyone, Owners included. CanNotDelete (Delete in the portal) lets people read and update but not delete; ReadOnly blocks every write, so it can also break things like listing storage account keys or scaling an App Service plan. Locks are set at subscription, resource group or resource scope, inherit to child resources, and removing one needs Microsoft.Authorization/locks/delete (Owner or User Access Administrator). Tags are name/value pairs (up to 50 per resource) used for cost, ownership and automation. Resource group tags aren't inherited by resources; use Azure Policy (Inherit a tag, Require a tag) to apply them at scale.

    Simulate it » No Azure account needed

    Exam objective: 1.3.2 Configure resource locks. 1.3.3 Apply and manage tags on resources. (Skills measured as of April 17, 2026)

    Simulations

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

    Azure portal: Add a resource lock and manage tags Add a Delete lock and tag a resource group.
    </> Embed

    Embed this simulation

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

    Loading the portal…

    Open <strong>rg-finance</strong> and, under <strong>Settings</strong>, select <strong>Locks</strong>.

    👆 Click the glowing item in the portal to continue

    Read the steps as text
    1. Open rg-finance and, under Settings, select Locks.
    2. No locks yet. Select + Add.
    3. Delete (CanNotDelete) allows changes but blocks deletion. Read-only blocks every write, even tags and some actions that sound like reads, such as listing storage keys.
    4. CLI: az lock create -n no-delete -t CanNotDelete -g rg-finance. Now Tags.
    5. Tags are name/value pairs. A resource group's tags aren't inherited by its resources unless a policy copies them.
    6. To tag many resources at once, select them in All resources and use Assign tags. At scale, the Inherit a tag from the resource group policy keeps everything consistent.
    7. Tags pay off in Cost analysis: group by tag costcenter and each department sees its share. Untagged spend is the gap to chase.

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

    😟 THE PROBLEM

    Someone deleted the production database resource group on a Friday evening.

    😊 THE SOLUTION

    Lock production against deletion and tag everything for ownership and cost.

    • Accidental deletes✓ CanNotDelete lock
    • Changes during an audit✓ ReadOnly lock for a short freeze
    • Who owns this?✓ owner and costcenter tags
    🛠️ Solved with: Resource locks and tags

    Start with a question

    How do museums stop anyone, even staff, from moving the most valuable painting?

    A museum puts the famous painting behind glass with a lock. Curators can still dim the lights and adjust the label, but nobody lifts it off the wall without first getting the key from security. During a stocktake they lock the whole room, so nothing gets touched at all. And every item has a little card saying who donated it and which gallery pays for its care.

    The glass case is a CanNotDelete lock, the locked room is a ReadOnly lock, and the little card is a set of tags.

    Explain it like I’m 10

    The technical explanation

    Resource locks

    CanNotDelete (portal: Delete)ReadOnly (portal: Read-only)
    ReadYesYes
    Update, tag, scale, startYesNo
    DeleteNoNo
    Side effectsFewBlocks POST actions like listing storage keys; can stop App Service, VMs and backups working normally
    Typical useProduction, always onShort freezes, audits
    • Scopes: subscription, resource group or resource. A lock on a parent applies to everything under it, including resources created later. The most restrictive lock wins.
    • Locks affect the control plane only. A CanNotDelete lock on a storage account doesn’t stop someone deleting a blob inside it.
    • Locks apply to everyone. To remove one you need Microsoft.Authorization/locks/delete, which Owner and User Access Administrator have and Contributor doesn’t.

    Portal: resource or group → Settings → Locks → + Add → Lock name, Lock type (Read-only or Delete), Notes.

    az lock create --name no-delete --lock-type CanNotDelete --resource-group rg-finance --notes "Finance production"
    az lock create --name freeze --lock-type ReadOnly --resource-group rg-finance \
      --resource-name stfin0424 --resource-type Microsoft.Storage/storageAccounts
    az lock list --resource-group rg-finance -o table
    az lock delete --name freeze --resource-group rg-finance --resource-name stfin0424 --resource-type Microsoft.Storage/storageAccounts
    New-AzResourceLock -LockName no-delete -LockLevel CanNotDelete -ResourceGroupName rg-finance

    Tags

    A tag is name: value, such as costcenter: FIN-042, env: prod, owner: finance-ops@contoso.com. Each resource, resource group or subscription can have up to 50 tags. Names are case-insensitive, values case-sensitive, and some resource types don’t support tags.

    az group update -n rg-finance --tags costcenter=FIN-042 env=prod     # replaces the group's tags
    az tag update --resource-id <id> --operation Merge --tags owner=finance-ops   # adds without wiping
    az resource tag -g rg-finance -n stfin0424 --resource-type Microsoft.Storage/storageAccounts --tags costcenter=FIN-042

    Use --operation Merge to add tags and keep the existing ones; Replace swaps the whole set and Delete removes the ones you list. You need write access to the resource or the Tag Contributor role to change tags. A ReadOnly lock blocks tag changes too.

    Tags at scale

    Resource group tags aren’t inherited. To make them stick everywhere:

    • Inherit a tag from the resource group if missing (Modify) copies the group’s tag to resources, with a remediation task for existing ones.
    • Require a tag on resources or on resource groups (Deny) forces people to supply one.
    • All resources → select → Assign tags tags many resources in the portal at once.
    • Cost Management’s tag inheritance setting applies group and subscription tags to cost records only, without changing the resources.
    1. 1 Lock

      CanNotDelete on rg-finance: deletes fail, changes still work.

    2. 2 Tag

      rg-finance gets costcenter=FIN-042 and owner=finance-ops.

    3. 3 Inherit

      A Modify policy copies costcenter onto every resource inside.

    4. 4 Report

      Cost analysis groups spend by costcenter for the monthly chargeback.

    Protect and label rg-finance
    Architect level Locks, deployments and automation

    ARM template and Bicep deployments in Complete mode try to delete resources that aren’t in the template, and a CanNotDelete lock will make that fail. Backup and Site Recovery need write access to restore points, so a ReadOnly lock on a VM’s resource group can break backups. Some services create their own locks; for example, a Recovery Services vault may add one. If automation must remove and re-add a lock, give its managed identity a narrow custom role with only the lock actions rather than Owner.

    Real-world business scenario

    Banking

    Woodgrove Bank (fictional)

    The problem
    A script cleaning up test resource groups matched the wrong name and deleted a production resource group, and nobody could tell which team owned half the remaining resources.
    What they used
    CanNotDelete locks on every production resource group (applied through a pipeline), owner and costcenter tags required on resource groups by a Deny policy, and the Inherit a tag policy copying them to resources. ReadOnly locks are used only during quarter-end audit freezes.
    Why that choice
    Scripts and people can still update production, but deletes fail until a platform admin removes the lock on purpose, and every resource shows an owner.
    The result
    No accidental production deletions since, and the chargeback report covers 98% of spend.

    When to use it and when not to

    ✓ Use it when…

    • CanNotDelete on production subscriptions, resource groups and shared networking.
    • ReadOnly for short, planned freezes.
    • Tags for cost center, owner, environment and automation schedules.

    ✕ Think twice when…

    • Long-term ReadOnly on resources that need normal operations (scaling, backups, key listing).
    • Relying on resource group tags to label resources without a policy.

    ↔ Alternatives to consider

    • Azure RBAC to stop specific people deleting things, rather than everyone.
    • Deployment stacks deny settings to protect everything a stack deployed.
    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

    Administrators must be able to resize virtual machines in RG1, but nobody must be able to delete RG1 or its resources. What should you configure?

    Question 2

    Question 2 of 5

    A ReadOnly lock is applied to a resource group that contains a storage account. Which operation fails?

    Question 3

    Question 3 of 5

    User1 is assigned the Contributor role on a resource group that has a CanNotDelete lock. User1 must delete a virtual machine in the resource group. What should happen first?

    Question 4

    Question 4 of 5

    Resource group RG1 has the tag costcenter=FIN-042. A new virtual machine is created in RG1 without tags. Which tags does the virtual machine have?

    Question 5

    Question 5 of 5

    You need to add the tag owner=ops to a storage account without removing its existing tags by using Azure CLI. Which command should you use?

    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 a Delete lock and a ReadOnly lock?

    Model answer

    A Delete lock, CanNotDelete, lets people keep working on the resource but stops anyone deleting it. ReadOnly stops any change at all, including tags. I use Delete on production all the time and ReadOnly only for short freezes.

    Intermediate Why might a ReadOnly lock break an app?

    Model answer

    Because some operations that feel like reads are actually POST requests in Azure Resource Manager. Listing storage account keys is one, so anything that reads keys through the management API fails. Scaling a plan, starting a VM or adding a tag also stop working.

    Experienced developer Do resource group tags flow down to resources?

    Model answer

    No, not by themselves. I'd assign the built-in Inherit a tag from the resource group if missing policy with a managed identity, plus a remediation task for existing resources. Cost Management also has a tag inheritance setting, but that only affects cost data, not the resources' actual tags.

    Scenario An Owner can't delete a resource group they created. What's going on?

    Model answer

    Almost certainly a lock, on the group or inherited from the subscription. Locks apply to everyone. They'd check Locks on the group and the subscription, remove it if that's the right call, then delete. If there's no lock, I'd check for a deny assignment from a deployment stack.

    Quick revision

    Key points

    • CanNotDelete = no deletes, updates allowed. ReadOnly = no writes at all.
    • Locks apply to every user, including Owners, and inherit from parent scopes.
    • Removing a lock needs Microsoft.Authorization/locks/delete (Owner, User Access Administrator).
    • Tags are name/value pairs, up to 50 per resource. Not every resource type supports tags.
    • Resource group tags don't flow to resources unless a policy copies them.

    Important terminology

    CanNotDelete lock
    Called Delete in the portal. Users can read and modify a resource but can't delete it.
    ReadOnly lock
    Users can read a resource but can't update or delete it. Some POST operations are blocked too.
    Lock inheritance
    A lock on a subscription or resource group applies to every resource inside it, including ones added later.
    Tag
    A name and value pair on a resource, resource group or subscription, such as costcenter = FIN-042.
    Tag inheritance
    Copying a resource group's or subscription's tag to its resources, done with Azure Policy or Cost Management tag inheritance.
    Tag Contributor
    A built-in role that can manage tags on resources without access to the resources themselves.

    Common mistakes

    • Putting ReadOnly on a busy production resource group and breaking normal operations.
    • Expecting resources to inherit a tag from their resource group automatically.

    Exam tips

    • "Prevent accidental deletion but allow changes" = CanNotDelete (Delete).
    • "Prevent any change" = ReadOnly.
    • "Every resource must carry its resource group's costcenter tag" = Inherit a tag policy (+ remediation).

    Five quick revision questions

    1. 1.Which lock still allows updates?Show

      CanNotDelete (Delete).

    2. 2.Does a lock stop an Owner?Show

      Yes. Locks apply to everyone.

    3. 3.Which command creates a lock on a resource group?Show

      az lock create --name ... --lock-type CanNotDelete --resource-group ...

    4. 4.How many tags can a resource have?Show

      Up to 50.

    5. 5.Are resource group tags inherited by resources by default?Show

      No.

    Official references

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

    Next up: Resource Groups, Subscriptions and Management Groups

    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.