Enable version-level immutability support for Azure Storage account with Terraform

Viewed 418

Is there a way to enable version-level immutability support and create time-based retention policy for Azure storage account-level with Terraform? All I am trying to do is to enable Access Control under Data Protection and set time based immutability policy. Seems simple, but I cannot find how to do that in TF.

1 Answers

From documentation here, it appears to me as a newly added feature?

It might take some time to get this packaged into azurerm provider. You can create a PR on their codebase or create a feature request to include this into azurerm_storage_blob.

In the meantime, you could use local-exec on above resource to execute az-cli commands.

resource "azurerm_storage_blob" "immutable-blob" {
  # ...

  provisioner "local-exec" {
    command = "az storage blob immutability-policy set \
        --expiry-time 2022-05-20T08:00:00Z \
        --policy-mode Unlocked \
        --container <container> \
        --name <blob-version> \
        --account-name <storage-account> \
        --auth-mode login"
  }
}
Related