Review Azure Blob container soft-delete retention

Configure Azure Blob container soft delete and sufficient retention to recover from deletion of an entire container.

Description

Container soft delete restores a deleted container with its contents. To recover a blob deleted from a container that still exists, use blob soft delete or versioning. Protect the storage account itself separately.

Potential impact

When container retention expires, the recovery window closes for all the blobs it contained. Restoring a large backup can take longer and cost more.

Remediation

Set days in blob_properties.container_delete_retention_policy to cover detection and recovery. Microsoft recommends at least seven days. Consider retention costs and test restoring a container under its original name, which must be available. Maintain backups and restrict deletion permissions.

Examples

Both examples set retention. They also use different account names, locations, tiers and replication settings. When adjusting an existing account, change only its retention and check the Terraform plan.

Before

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

  blob_properties {
    container_delete_retention_policy {
      days = 5
    }
  }
}

The first account keeps deleted containers for five days.

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 {
    container_delete_retention_policy {
      days = 49
    }
  }
}

The second keeps them for 49 days, allowing more time to discover and recover from deletion.

References