Exercise: Configure a resource lock

Natasha Ong
This is some text inside of a div block.
4 min read

Exercise Overview:

In this exercise, you will:

  • Create a resource.
  • Apply a read-only resource lock.
  • Apply a delete resource lock.
  • Delete a resource lock.

Task 1: Create a resource

Before we can see a resource lock in action, let's create a resource first!

  1. In the Azure portal, select Create a resource.
  2. Under Categories, select Storage.
  3. Under Storage Account, select Create.
  4. On the Basics tab of the Create storage account page, leave the default option for everything except for these settings.
  1. Select Review + Create.
  2. Once validated, select Create.
  3. Wait for the notification that the account was successfully created. Time for a leg stretch!
  4. Select Go to resource.

Task 2: Apply a read-only resource lock

  1. Before we start - what impact do you think a read-only resource lock will have on the storage account? Give yourself a minute to recap what you've learned.
  2. Scroll down until you find the Settings section in the left hand navigation panel.
  3. Select Locks.
  4. Select + Add.
Screenshot of the Add lock feature on a storage account set for a read-only lock.
  1. Enter a Lock name.
  2. Make sure the Lock type is set to Read-only.
  3. Select OK.

Task 3: Add a container to the storage account

In this task, you'll add a container to the storage account to store blobs.

  1. Select Containers in the left hand navigation panel. You might need to scroll to find it!
  2. Select + Container.
Screenshot of the add container process outlined in this task.

3. Enter a container name and select Create.

4. You should get an error message: Failed to create storage container.

Screenshot of the Failed to create storage container error message.

The error message lets you know that you couldn't create a storage container because a lock is in place. The read-only lock prevents any create or update actions on the storage account.

Task 4: Modify the resource lock

  1. Head back to Locks in your left hand navigation panel.
  2. Select the read-only resource lock you created.
  3. Change the Lock type to Delete and select OK.
Screenshot midway through task process of changing the lock type on a resource lock.

4. Head back to the Containers page.

5. Select + Container again.

6. Enter a container name and select Create.

7. Voila! Your storage container should appear in your list of containers.

So now that we changed our resource lock to a Delete lock, you can create and update things in your storage account. Deleting the resource lock itself would have the same effect.

Task 5: Delete the storage account

  1. Select Overview at the left hand navigation panel. You might need to scroll up to find it!
  2. Select Delete.
Screenshot of the deletion process for deleting a storage account.

3. You should get a notification that says you can't delete the resource because it has a delete lock.

Screenshot of the Delete storage account error, explaining that a resource lock prevents deletion.

Task 6: Delete the resource lock and storage account

In this final task, let's remove the resource lock and delete the storage account from your Azure account.

  1. Challenge yourself first! Do you think you can delete the lock and storage account without any guidance?
  2. Select Locks from the left hand navigation panel.
  3. Select Delete.
  4. Head back to the home page in your Azure portal.
  5. Select Storage accounts.
  6. Select the storage account you used for this exercise.
  7. Select Delete.
  8. Enter the name of the storage account, and select Delete.
Screenshot of the deletion confirmation message before deleting a storage account.

9. Check that your storage account was deleted. Head back to the storage accounts page, and you should find that the storage account you've created is gone.


You've just configured, updated, and removed a resource lock on an Azure resource.

  • Make sure you've removed the storage account so that you don't rack up any charges!