DEV Community

Peter Edozie
Peter Edozie

Posted on

Manage resource locks

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
  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 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

  1. 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

  • 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

  1. 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
  2. Click Review + Create to review your storage account settings and allow Azure to validate the configuration.
  3. Once validated, click Create. Wait for the notification that the account Deployment Succeeded.
  4. Access your new storage account and from the Overview pane, click Delete. Image description

You receive an error message stating the resource or its parent has a delete lock.
Image description
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

  1. Return to the storage account blade and confirm you can now delete the resource. Image description

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.

Top comments (0)