how to add the property to delete the blob versions after X days in terraform

131 views Asked by At

I want to enable versioning of blobs in storage account and also to delete the versions after 7 days. The blob versioning is enabled using the property "versioning_enabled", But I dont see any option to add the property to delete the versions after X days.

I see options for "delete_retention_policy" but this doesnot apply to the versions. It gets applied to "enable soft delete of blobs" and sets the property for "how many days to retain the deleted blob".

So does terraform not provide this option of setting this property? Or is there any other way to do this via terraform.

1

There are 1 answers

0
leovigildorex On

You need something like this:

resource "azurerm_storage_management_policy" "example" {
  storage_account_id = azurerm_storage_account.example.id

  rule {
    name    = "appservice-logs-retention"
    enabled = true
    filters {
      prefix_match = ["log-files/AppServiceHTTPLogs"]
      blob_types   = ["blockBlob"]
    }
    actions {
      base_blob {
        delete_after_days_since_modification_greater_than = 5
      }
    }
  }
}