Review Azure file share soft delete

Verify Azure file share soft delete and retention so an entire deleted share can be recovered.

Description

For classic Azure file shares in a storage account (Microsoft.Storage), soft delete restores a deleted share and its contents. To recover individual files deleted from a share that still exists, use share snapshots or backups. New storage accounts enable share soft delete by default.

Potential impact

If a deleted share is no longer recoverable, applications that use its mounted path can remain unavailable while you restore from backup.

Remediation

Check the account’s effective share protection and set days in share_properties.retention_policy. Choose a window that covers detection and recovery, consider storage costs, and test restoring a share within it. Restrict permissions to delete shares and accounts.

Examples

The excerpts use different account names, locations and replication settings. To change retention on an existing account, keep its other settings and confirm the Terraform plan will update it in place.

Before

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

  share_properties {
  }
}

The empty share_properties block leaves retention unspecified in the excerpt. Check the deployed setting.

After

hcl
resource "azurerm_storage_account" "storage_account" {
  name                     = "filesharestore02"
  resource_group_name      = "testRG"
  location                 = "northeurope"
  account_tier             = "Standard"
  account_replication_type = "LRS"

  share_properties {
    retention_policy {
      days = 7
    }
  }
}

The second account explicitly retains deleted shares for seven days. Extend the period if recovery needs more time.

References