Lock a resource group against deletion
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
- Resource groups
- rg-portal-practice
- Locks
- + Add
Steps
- Open rg-portal-practice and select Locks under Settings in the left menu.
- Select + Add.
- 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.
- 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.
- 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
- rg-portal-practice
- 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