How to Create a Resource Lock in Microsoft Azure
Tags: cloud, devops, azure, kubernetes
Published: 2023-03-21 15:19:50

Resource Locks in Microsoft Azure are powerful protection mechanism that can prevent modification or deletion of resources from an unauthorised source. It provides a method to lock subscriptions, resource groups or individual resources to protect them from intentional or accidental deletion and modification.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ihu0sj4qzuoiw375mcrt.png)

Steps to Create a Resource Lock:

Step 1:
- Create a Microsoft Azure account and login
- Navigate to https://azure.microsoft.com/
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i5pc29kifwp7ybnu9fdq.png)

Step 2:
- Click on Resource Group or search for Resource Group in the 
  search bar, in case you don't find it on your portal
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o7oful2k5ctou2d2w3f4.png)

Step 3:
- Click on Create
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tt6q98wl2ej6t47p67ag.png)

Step 4:
- Subscription: Choose your subscription
- Resource Group: Choose a name of your choice
- Region: Any region or your region
- Review and Create
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wockit440fqidw80iwnn.png)

Step 5:
- Click on Create
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x7os1emsa0hauomr8jky.png)

Step 6:
Your Resource Group is created
- Click on it to access it
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q83cebnf85arf5t42iuv.png)

Step 7:
To add a Lock to your Resource Group
- Click on Lock
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/clt2ie3oe3zzesjyeva6.png)

Step 8:
- Click on Add
- Lock name: Choose any name
- Lock type: Choose Read Only or Delete; depending on the type of lock you intend to achieve
- Notes: Optional but it helps to reiterate your message
- Click OK
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4by2escg22xs8eo7p9e4.png)

Step 9:
Click Home to create a Storage Account
- Click Storage Account
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9olxbtpeyep66b1gya23.png)

Step 10:
- Create
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3xum0d1zel2gy8la453q.png)

Step 11:
- Subscription: Choose your subscription
- Resource Group: Ensure you choose the resource group you want to lock. Using it means you're saving your storage account in the resource group
- Storage Account Name: Choose a unique name across all existing 
accounts in Azure
- Region: Choose your region
- Click Review


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aqv3xkyakss6at6862k9.png)

Step 12:
- Create

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tpef2ejbldnc7ykpyy04.png)

Step 13:
Storage account is created
- Click on 'Go to resource' to view

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/95d1rjrzfmrr355cy2r4.png)

Step 14:
Try to delete and see the error message
- Click on Delete in order to test if your resource group lock worked
- Copy the resource group name
- Paste in the arrow part on the right bottom of your screen
- Delete
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ftnoqre43u9s77v1y6zl.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jmrv7et1bmzor7i0bni4.png)

Step 15:
The error message is because of the locks on the resource group Locks must be removed before resource can be deleted
This implies that the resource was locked correctly
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r1hxpybw34yaryxsei0c.png)

Step 16:
The way to successfully remove a lock resource:
- Go to Home and click on the resource group
- Click on Locks
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e0g99dx4fpxdl8movnrn.png)

Step 17:
- Click on Delete
- You can also change the lock type to 'Read Only' by clicking on 'edit' close to 'delete'
- See the 2nd picture to view what pops up if you want to change the lock type

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jv4qtp2myre9uxokctkm.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9kwvhpepy6d7d8zz3kzv.png)

Step 18:
Go back to the resource group and try to delete the storage account after the removing the lock
- Storage account was deleted successfully because of the removal of the locks
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/59pfzadk7fn8lo5d567w.png)