Lock a resource group against deletion

Azure Portal, Hands On5 minutesFreeSteps checked 17 October 2026By Cloud Hands On

In this task you'll add a delete lock to a resource group.

A lock stops resources being deleted or changed by accident, even by people with the Owner role. A Delete lock allows changes but blocks deletion. A Read-only lock blocks changes too.

A lock on a resource group applies to every resource inside it.

Example. Larkfield Group puts a Delete lock on the resource group that holds its live customer database, so a tidy-up script can't remove it by mistake.

Before you start

You need: Owner or User Access Administrator. Time: 5 minutes.

Where to look

  1. Resource groups
  2. rg-portal-practice
  3. Locks
  4. + Add

Steps

  1. Open rg-portal-practice and select Locks under Settings in the left menu.
  2. Select + Add.
  3. Name it lock-no-delete, change Lock type to Delete, add a note such as 'Practice lock' and select OK.Lock type starts on Read-only, which blocks all changes. Make sure it says Delete.
  4. Go back to Overview, select Delete resource group, type the name and confirm.This is a test. The notification should say Failed to delete resource group, because it has locks applied.
  5. Return to Locks, select Delete at the end of the lock-no-delete row (scroll right in a narrow window) and confirm.

Commands

# Add a delete lock
az lock create --name lock-no-delete --lock-type CanNotDelete \
  --resource-group rg-portal-practice --notes "Practice lock"

# Remove it again
az lock delete --name lock-no-delete --resource-group rg-portal-practice

Watch out for

Cost
Locks are free.
Security
Locks protect against mistakes, not attackers. Anyone with Owner can remove a lock and then delete, so keep the Owner role for very few people.
Common mistakes
A Read-only lock can break things in surprising ways, because some actions that look like reading are really changes behind the scenes. For example, nobody can list a storage account's keys. Use Delete locks unless you're sure.

Clean up

  1. rg-portal-practice
  2. Locks

Remove the lock before you delete the resource group, or the clean-up will fail.

Words to know

Lock
A setting that blocks deletion, or all changes, on a resource or group, for everyone.

Tick off each step and track your progress in the guide.

Open this task in Azure Portal, Hands On

Keep going