Manage resource locks
Tags: azure, beginners, career, cloud
Published: 2022-05-19 11:37:31


 **Resource group** - A container that holds related resources for an Azure solution. The resource group can include all the resources for the solution, or only those resources that you want to manage as a group. You decide how you want to allocate resources to resource groups based on what makes the most sense for your organization.

In this walkthrough, we will add a lock to the resource group and test deleting the resource group. Locks can be applied in a subscription to resource groups, or individual resources to prevent accidental deletion or modification of critical resources.

- **Add a Lock to the resource group and test deletion**

We will add a resource lock to the resource group and test deleting the resource group.

1. Sign in to the Azure Portal
2. In the Azure portal, navigate to the resource group.![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ue5hn2o5xh8ghhrhqka6.png)
3. You can apply a lock to a subscription, resource group, or individual resource to prevent accidental deletion or modification of critical resources. 
4. In the Settings section, click Locks, and then click + Add.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rnik8imgvo29f9c4wvad.jpeg)
5.Configure the new lock. When selecting the lock type you notice the **Read-only** and **Delete**. Read only means authorized users can read a resource, but they can not delete or update the resource, while the **Delete** means authorized users can read and modify a resource, but they can not delete the resource. 
When you are done click OK.

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

6. Click **Overview** and click **Delete resource group**. Type the name of the resource group and click **Delete**. You receive an error message stating the resource group is locked and can’t be deleted.

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

- **Test deleting a member of the resource group**

We will test if the resource lock protects a storage account in the resource group.

1. From Search bar, Search for and select **Storage accounts**, and then click **+ Create**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/clveu5opbbk8494cs979.png
 )
 
2. On the Storage Accounts page +Create, fill in the following information (pick the name of the resource group that was lock earlier and the storage account name with letters such that the name is globally unique). Leave the defaults for everything else.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hmm394zz498iyud73423.png)
3. Click **Review + Create** to review your storage account settings and allow Azure to validate the configuration.
4. Once validated, click Create. Wait for the notification that the account Deployment Succeeded.
5. Access your new storage account and from the **Overview** pane, click **Delete**. 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b69g0f7yzmvhe5ccg8v0.png)

 You receive an error message stating the resource or its parent has a delete lock.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7429tjw1mko4vr98g1fd.png)
 **Note:** Although we did not create a lock specifically for the storage account, we did create a lock at the resource group level, which contains the storage account. As such, this parent level lock prevents us from deleting the resource and the storage account inherits the lock from the parent.

- **Remove the resource lock**

We will remove the resource lock and test. 

1. Return to the resource group **myRGLocks**, in the Settings section, click **Locks** and Click **Delete**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g4qvdy9gqm0mbypqf016.jpeg)
2. Return to the storage account blade and confirm you can now delete the resource.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q9iwav48sl98r3mac5gu.png)

Congratulations! You created a resource group, added a lock to resource group and tested deletion, tested deleting a resource in the resource group, and removed the resource lock.

**Note:** To avoid additional costs, you can optionally remove this resource group. Search for resource groups, click your resource group, and then click **Delete resource group**. Verify the name of the resource group and then click **Delete**. Monitor the Notifications to see how the delete is proceeding.