Description
An Azure CanNotDelete management lock blocks control-plane deletion of a storage account, including by users with delete permission. Locks can apply directly or be inherited from a resource group or subscription. They do not block data-plane operations such as deleting a blob.
Potential impact
Deleting an account can interrupt applications, log collection and backups. Users permitted to remove its lock can still remove that protection.
Remediation
Check locks on the account, resource group and subscription. If deletion protection is required and no lock applies, add azurerm_management_lock with lock_level = "CanNotDelete" at the intended scope. Keep an existing ReadOnly lock if changes must also be blocked. Review who can remove locks, and use separate data access controls and recovery features.
Examples
Both excerpts omit required account settings such as resource_group_name.
Before
resource "azurerm_storage_account" "example" {
name = "examplestorageacct"
location = azurerm_resource_group.example.location
account_tier = "Standard"
account_replication_type = "LRS"
}
After
resource "azurerm_storage_account" "example" {
name = "examplestorageacct"
location = azurerm_resource_group.example.location
account_tier = "Standard"
account_replication_type = "LRS"
}
resource "azurerm_management_lock" "storage_delete_lock" {
name = "storage-delete-lock"
scope = azurerm_storage_account.example.id
lock_level = "CanNotDelete"
notes = "Prevent accidental deletion of the storage account"
}
Explanation:
- Before: No account lock is shown. Check for inherited locks before adding one.
- After:
scopepoints to the storage account ID. The lock blocks deletion of that account while it is in place.