Review Azure Blob soft-delete retention

Configure Azure Blob soft delete and retention to allow time to discover deletion and recover data.

Description

Blob soft delete lets you recover deleted blobs, snapshots and versions during retention. A deleted container needs container soft delete, and the storage account needs its own deletion protection.

Potential impact

If you discover a deletion after retention expires, restoring from backup or uploading the data again can delay recovery.

Remediation

Set days in blob_properties.delete_retention_policy to cover the time needed to detect a deletion and restore the data. Weigh retention costs against the data’s importance and test a restore. Review versioning, backups and who can delete the account.

Examples

Both examples enable soft delete. They also change the account name, resource group, location, tier and replication. To update only retention on an existing account, keep its other settings and check the Terraform plan for replacement.

Before

hcl
resource "azurerm_storage_account" "storage_account" {
  name                     = "appstorage001"
  resource_group_name      = azurerm_resource_group.example.name
  location                 = azurerm_resource_group.example.location
  account_tier             = "Standard"
  account_replication_type = "GRS"

  blob_properties {
    delete_retention_policy {
      days = 5
    }
  }
}

A deleted blob can be recovered for five days in this example.

After

hcl
resource "azurerm_storage_account" "storage_account" {
  name                     = "protectedstore01"
  resource_group_name      = "testRG"
  location                 = "northeurope"
  account_tier             = "Premium"
  account_replication_type = "LRS"

  blob_properties {
    delete_retention_policy {
      days = 49
    }
  }
}

The second account specifies 49 days. Choose a window that meets your recovery needs.

References