Bylaw

Gallery › Storage › Azure Community Policy

Configure Storage Account to have Container Soft Delete enabled

Doesn't convert yet Policy Audit Deny Disabled Modify Mode All Version 1.0.0

Container soft delete protects your data from being accidentally or erroneously modified or deleted. When container soft delete is enabled for a storage account, a container and its contents may be recovered after it has been deleted, within a retention period that you specify. For more details about container soft delete, see https://learn.microsoft.com/en-us/azure/storage/blobs/soft-delete-container-overview.

ConvertTo-Bylaw can't convert this policy yet:

Azure Policy JSONazurepolicy.json · 92 lines
{
  "name": "c54a8309-0007-4287-87ae-1db2dfd5b14c",
  "type": "Microsoft.Authorization/policyDefinitions",
  "properties": {
    "displayName": "Configure Storage Account to have Container Soft Delete enabled",
    "description": "Container soft delete protects your data from being accidentally or erroneously modified or deleted. When container soft delete is enabled for a storage account, a container and its contents may be recovered after it has been deleted, within a retention period that you specify. For more details about container soft delete, see https://learn.microsoft.com/en-us/azure/storage/blobs/soft-delete-container-overview.",
    "metadata": {
      "version": "1.0.0",
      "category": "Storage"
    },
    "mode": "All",
    "parameters": {
      "retentionInDays": {
        "type": "Integer",
        "defaultValue": 1,
        "metadata": {
          "displayName": "Retention in Days",
          "description": "How long should deleted resources be retained for. Minimum value is 1 day, maximum is 365 days."
        }
      },
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Modify, Deny, Audit or Disabled the execution of the Policy"
        },
        "allowedValues": [
          "Modify",
          "Deny",
          "Audit",
          "Disabled"
        ],
        "defaultValue": "Modify"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Storage/storageAccounts/blobServices"
          },
          {
            "anyOf": [
              {
                "allOf": [
                  {
                    "value": "[requestContext().apiVersion]",
                    "less": "2022-05-01"
                  },
                  {
                    "field": "Microsoft.Storage/storageAccounts/blobServices/containerDeleteRetentionPolicy.enabled",
                    "equals": false
                  }
                ]
              },
              {
                "field": "Microsoft.Storage/storageAccounts/blobServices/containerDeleteRetentionPolicy.enabled",
                "exists": false
              },
              {
                "field": "Microsoft.Storage/storageAccounts/blobServices/containerDeleteRetentionPolicy.enabled",
                "equals": false
              }
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "conflictEffect": "audit",
          "roleDefinitionIds": [
            "/providers/Microsoft.Authorization/roleDefinitions/17d1049b-9a84-46fb-8f53-869881c3d3ab"
          ],
          "operations": [
            {
              "operation": "addOrReplace",
              "field": "Microsoft.Storage/storageAccounts/blobServices/containerDeleteRetentionPolicy.enabled",
              "value": true
            },
            {
              "operation": "addOrReplace",
              "field": "Microsoft.Storage/storageAccounts/blobServices/containerDeleteRetentionPolicy.days",
              "value": "[parameters('retentionInDays')]"
            }
          ]
        }
      }
    }
  }
}

Source: policyDefinitions/Storage/configure-storage-account-to-have-container-soft-delete-enabled/azurepolicy.json in Azure/Community-Policy, under the MIT licence.