Best Practice for ADLS Gen2 (HNS) Soft Delete in Terraform: Explicit Configuration vs. Relying on Platform Defaults (blob_properties)

S, Maheshwari 0 Reputation points
2026-08-14T08:55:24.01+00:00

Hello,

We are currently deploying an Azure Storage Account with Hierarchical Namespace (HNS) enabled (ADLS Gen2) for a production environment using Terraform (azurerm provider).

We are facing a design debate regarding data protection (Soft Delete) and would appreciate the Microsoft community's guidance on best practices.

The Scenario:

Our upstream Terraform module statically defines the restore_policy block inside blob_properties like this:

# Upstream Module Code
resource "azurerm_storage_account" "sa" {
  # ... other configurations ...
  blob_properties {
    delete_retention_policy {
      days = var.delete_retention_policy_days
    }
    restore_policy {
      days = var.restore_policy_days
    }
    versioning_enabled = var.versioning_enabled
  }
}

The Problem:

Since HNS (ADLS Gen2) is enabled, we cannot use Point-in-Time Restore (restore_policy) or Versioning. However, because the restore_policy block is statically defined in the module, running terraform apply fails with the following provider validation error: Error: versioning_enabled must be true when restore_policy is set


Proposed Workaround A (Developer's Approach):

To bypass this error without updating the upstream module code, a team member has proposed setting blob_properties = [] (passing an empty block) in our root configuration inputs.

Their arguments are:

  1. Leaving blob_properties empty allows the storage account to deploy using Azure's native platform defaults.
  2. Since Azure enables Blob Soft Delete by default on new storage accounts, we do not need to explicitly define or manage the 7-day soft delete policy in our Terraform code.

Proposed Solution B (Our Approach - Module Refactor):

We proposed refactoring the upstream module to make the restore_policy block dynamic. This allows us to completely omit the block when restore_policy_days is set to null, while still explicitly managing our 7-day soft delete policy:

# Proposed Module Refactor
resource "azurerm_storage_account" "sa" {
  # ... other configurations ...
  blob_properties {
    delete_retention_policy {
      days = var.delete_retention_policy_days
    }

With this refactor, we can set restore_policy_days = null in our root inputs. The block is completely dropped, the provider validation error is bypassed, and our 7-day soft delete remains explicitly managed in code.

  1. Our Concerns:

    We believe that omitting blob_properties and relying on platform defaults is a risk for a production environment.
    1. Is it considered an Azure Best Practice to rely on "platform defaults" for critical data protection features like Soft Delete in production, or should they be explicitly declared and managed via Infrastructure as Code (IaC)?
    2. What are the risks of leaving blob_properties unmanaged in Terraform?
    3. Does ADLS Gen2 (HNS) fully support Blob and Container Soft Delete, and is it recommended to keep them explicitly enabled for production data lakes?
Azure Data Lake Storage
Azure Data Lake Storage

An Azure service that provides an enterprise-wide hyper-scale repository for big data analytic workloads and is integrated with Azure Blob Storage.


1 answer

Sort by: Oldest
  1. AI answer

    2026-08-14T08:55:49.7233333+00:00

    For an HNS-enabled ADLS Gen2 storage account, the safer approach is to explicitly manage supported data-protection settings and omit unsupported ones.

    restore_policy should be omitted for this scenario. Point-in-time restore is not supported for HNS/ADLS Gen2, and blob versioning is also not supported for accounts that have a hierarchical namespace. That aligns with the provider validation failure requiring versioning_enabled = true when restore_policy is set.

    Explicitly managing soft delete is the better production practice here:

    1. Blob soft delete and container soft delete are both supported for HNS-enabled accounts.
    2. Blob soft delete is disabled by default and must be enabled at the storage account level.
    3. Microsoft recommends enabling blob soft delete for all storage accounts, with a minimum retention interval of seven days.
    4. Microsoft also recommends enabling container soft delete, with a minimum retention interval of seven days.

    For ADLS Gen2 specifically:

    • Blob soft delete on HNS-enabled accounts protects delete operations.
    • Blob versioning is not available for HNS-enabled accounts.
    • Container soft delete is available for Data Lake Storage.
    • Container soft delete restores deleted containers and their contents, but it does not restore an individual blob deleted from a container.

    That means the production-oriented design is:

    • keep blob_properties.delete_retention_policy explicitly configured
    • omit restore_policy
    • do not enable versioning on HNS accounts
    • also explicitly enable container soft delete if container recovery is required

    Risks of leaving blob_properties unmanaged and relying on defaults:

    1. Soft delete may not be enabled, because blob soft delete is disabled by default.
    2. The retention period is not explicitly controlled in code, which weakens repeatability and auditability.
    3. Drift becomes harder to detect because the intended protection posture is not declared in Terraform.
    4. Production recovery expectations can be missed if a deployment succeeds without the required retention settings.

    On the specific debate:

    • Workaround A is not a best-practice choice for production data protection because it leaves a critical recovery setting unmanaged and depends on platform behavior instead of declared configuration.
    • Solution B is the correct pattern: refactor the module so unsupported features such as restore_policy are omitted for HNS accounts, while supported protections such as soft delete remain explicitly configured.

    A practical target configuration for HNS/ADLS Gen2 production is:

    1. Blob soft delete enabled with at least 7 days retention.
    2. Container soft delete enabled with at least 7 days retention.
    3. No blob versioning.
    4. No point-in-time restore.
    5. If stronger protection against deletion or overwrite is required, consider immutability policies or account-level protections such as ARM locks, depending on the scenario.

    References:

    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.