Manage resource locks
Tags: locks, azure, beginners, resourcegroups
Published: 2022-05-12 21:24:55

As an administrator, you can lock a subscription, resource group, or individual resource to prevent other users in the organisation from accidentally deleting or modifying resources. A lock overrides any permissions the user might have.

In this walkthrough, we will add a lock to a **resource group** and test deleting the resource group. A resource group is a container to manage and aggregate resources in a single unit. You group related resources such as virtual machines, storage accounts and virtual networks.

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

1. Sign in to the the [Azure portal](https://portal.azure.com)
2. In the Azure portal, type in resource group in the search bar and select **Resource groups** under **Services**
![resource groups](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/26yisbbsk944d2zsu32s.png) This would list out the names of the resource groups created and available
3. Select any of the resource groups available for this task
4. In the **Settings** section, click **Locks** and then select **+ Add**
![resource group with lock](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eu9e2hqmzl78dlb1khdj.png)
5. Configure the new lock with the following and select **OK** when you are done
![Lock settings](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pl0lb0hdvbmteiq6c8vx.png)
![Lock type](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4o1k27dh76h9iwpsb7wy.png)**You would notice the lock has two types, **the Read-only** and **Delete**.
**Read only** means authorised users can read a resource, but they can not delete or update the resource, while the **Delete** means authorised users can read and modify a resource, but they can not delete the resource.
6. Select **Overview** and click **Delete resource group**. Type the name of the resource group and click **OK**
![Overview](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kihqp4ikhdsqn49n31i7.png)
7. You will receive an error message stating the resource group is locked and can not be deleted
![Delete RG failed](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k4avza65d8ydq6gbzukl.png)

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

We will test if the resource lock protects a storage account in the resource group. Read more about storage account [here](https://dev.to/toluehi/azure-storage-account-1g5f).
1. From the search box, type storage accounts and select **Storage accounts** under **Services**
![storage accounts](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dfkfk67sih4gd40vods4.png)
2. On the Storage accounts page, click **+Create** and fill in the following information. The storage account name must be a globally unique name.
![create storage account](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2uoyy50ets9255b8vvbr.png)
![storage settings](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/91qcq0ziqzqbm0gzbhzs.png)
![storage account page](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w3xo2bttglmdhvlyvfd7.png)
3. Select **Review + Create** to review your storage account settings and allow the configuration to be validated.
4. Once validated, click **Create** and wait for the notification that the storage account was successfully created.
5. Access your new storage by selecting **Go to resource**. From the **Overview** pane, click **Delete**
![Delete lock](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bfvt6tdylqzjlk1glvaf.png)
6. You will receive an error message stating the resource or its parent has a delete lock.
![Error message](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i1trn0iyfolplb25q7qy.png)
**Note:** We did not create a lock specifically for the storage account but we did create a lock at the resource group level which contains the storage account. As such, the parent level lock prevents us from deleting the resource and the storage accounts inherits the lock from the parent.

**- Remove the resource lock**

1. Return to the resource group 'myAZLocks' and in the **Settings** section, select **Locks**
2. Select **Delete** of 'Azlock'
![settings section](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vov8wiyzpbvvjyko9ht2.png)
3. Return to the storage account page and confirm you can now delete the resource

**Congratulations!** We just added a lock to a resource group and tested deletion, tested deleting a resource in the resource group and removed the resource lock.












****