Terraform-provider-azurerm: Support for Azure Storage Account Data protection

Created on 27 Aug 2020  路  2Comments  路  Source: terraform-providers/terraform-provider-azurerm

Community Note

  • Please vote on this issue by adding a 馃憤 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Description

Azure Storage Accounts now support some Data-Protection configurations, for example versioning or soft deletion for blob-storages.

Would be great if this could be configured with Terraform as well.

New or Affected Resource(s)

  • azurerm_storage_account

Potential Terraform Configuration

resource "azurerm_storage_account" "example" {
  name                     = "examplestoracc"
  resource_group_name      = azurerm_resource_group.example.name
  location                 = azurerm_resource_group.example.location
  account_tier             = "Standard"
  account_replication_type = "LRS"
  data_protection = {
    turn_on_versioning         = true
    turn_on_soft_deletion      = true
    keep_deleted_blobs_in_days = 7
    ...
  }
}

References

  • https://docs.microsoft.com/en-us/azure/storage/blobs/versioning-overview?tabs=powershell

  • https://docs.microsoft.com/en-us/azure/storage/blobs/soft-delete-blob-overview
  • https://docs.microsoft.com/en-us/azure/storage/blobs/soft-delete-container-overview
  • enhancement sdrequires-newer-api-version servicstorage

    Most helpful comment

    Upvoting, this has been available for a while now: https://azure.microsoft.com/en-gb/updates/azure-blob-versioning-is-now-general-available/

    Current work around (not hugely ideal)

    resource "azurerm_template_deployment" "asdf" {
        name                     = "asdf"
        resource_group_name      = azurerm_resource_group.asdf.name
        deployment_mode          = "Incremental"
        parameters               = {
            "storageAccount"     = azurerm_storage_account.asdf.name
        }
    
        template_body = <<DEPLOY
            {
                "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
                "contentVersion": "1.0.0.0",
                "parameters": {
                    "storageAccount": {
                        "type": "string",
                        "metadata": {
                            "description": "Storage Account Name"}
                    }
                },
                "variables": {},
                "resources": [
                    {
                        "type": "Microsoft.Storage/storageAccounts/blobServices",
                        "apiVersion": "2019-06-01",
                        "name": "[concat(parameters('storageAccount'), '/default')]",
                        "properties": {
                            "IsVersioningEnabled": true
                        }
                    }
                ]
            }
        DEPLOY
    }
    

    All 2 comments

    Upvoting, this has been available for a while now: https://azure.microsoft.com/en-gb/updates/azure-blob-versioning-is-now-general-available/

    Current work around (not hugely ideal)

    resource "azurerm_template_deployment" "asdf" {
        name                     = "asdf"
        resource_group_name      = azurerm_resource_group.asdf.name
        deployment_mode          = "Incremental"
        parameters               = {
            "storageAccount"     = azurerm_storage_account.asdf.name
        }
    
        template_body = <<DEPLOY
            {
                "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
                "contentVersion": "1.0.0.0",
                "parameters": {
                    "storageAccount": {
                        "type": "string",
                        "metadata": {
                            "description": "Storage Account Name"}
                    }
                },
                "variables": {},
                "resources": [
                    {
                        "type": "Microsoft.Storage/storageAccounts/blobServices",
                        "apiVersion": "2019-06-01",
                        "name": "[concat(parameters('storageAccount'), '/default')]",
                        "properties": {
                            "IsVersioningEnabled": true
                        }
                    }
                ]
            }
        DEPLOY
    }
    

    The turn_on_soft_deletion you can do today with a delete_retention_policy:

    resource "azurerm_storage_account" "storage_account_attachments" {
      ...
      blob_properties {
        delete_retention_policy {
          days = 365
        }
      }
    }
    
    Was this page helpful?
    0 / 5 - 0 ratings