Bylaw

Gallery › Resilience › Azure built-in policies

[Preview]: Storage Accounts should be Zone Redundant

Converted Policy Audit Deny Disabled Mode Indexed Version 1.0.0-preview Preview

Storage Accounts can be configured to be Zone Redundant or not. If a Storage Account's SKU name does not end with 'ZRS' or its kind is 'Storage,' it is not Zone Redundant. This policy ensures that your Storage Accounts use ae Zone Redundant configuration.

ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.

Azure Policy JSONStorage_storageAccounts_ZoneRedundant_Audit.json · 59 lines
{
  "properties": {
    "displayName": "[Preview]: Storage Accounts should be Zone Redundant",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "Storage Accounts can be configured to be Zone Redundant or not. If a Storage Account's SKU name does not end with 'ZRS' or its kind is 'Storage,' it is not Zone Redundant. This policy ensures that your Storage Accounts use ae Zone Redundant configuration.",
    "metadata": {
      "category": "Resilience",
      "version": "1.0.0-preview",
      "preview": true
    },
    "version": "1.0.0-preview",
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "This parameter lets you choose the effect of the policy. If you choose Audit (default), the policy will only audit resources for compliance. If you choose Deny, the policy will deny the creation of non-compliant resources. If you choose Disabled, the policy will not enforce compliance (useful, for example, as a second assignment to ignore a subset of non-compliant resources in a single resource group)."
        },
        "allowedValues": [
          "Audit",
          "Deny",
          "Disabled"
        ],
        "defaultValue": "Audit"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Storage/storageAccounts"
          },
          {
            "anyOf": [
              {
                "field": "Microsoft.Storage/storageAccounts/sku.name",
                "notLike": "*ZRS"
              },
              {
                "field": "kind",
                "equals": "Storage"
              }
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.0.0-PREVIEW"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/85b005b2-95fc-4953-b9cb-f9ee6427c754",
  "name": "85b005b2-95fc-4953-b9cb-f9ee6427c754"
}
Bylaw85b005b2-95fc-4953-b9cb-f9ee6427c754.bylaw.ps1 · 33 lines
# Converted from Storage_storageAccounts_ZoneRedundant_Audit.json by ConvertTo-Bylaw.
Policy '85b005b2-95fc-4953-b9cb-f9ee6427c754' {

    Properties @{
        DisplayName   = '[Preview]: Storage Accounts should be Zone Redundant'
        Description   = 'Storage Accounts can be configured to be Zone Redundant or not. If a Storage Account''s SKU name does not end with ''ZRS'' or its kind is ''Storage,'' it is not Zone Redundant. This policy ensures that your Storage Accounts use ae Zone Redundant configuration.'
        Category      = 'Resilience'
        Version       = '1.0.0-preview'
        Preview       = $true
        PolicyVersion = '1.0.0-preview'
        Mode          = 'Indexed'
    }

    Parameter Effect @{
        AllowedValues = @('Audit', 'Deny', 'Disabled')
        Default       = 'Audit'
        DisplayName   = 'Effect'
        Description   = 'This parameter lets you choose the effect of the policy. If you choose Audit (default), the policy will only audit resources for compliance. If you choose Deny, the policy will deny the creation of non-compliant resources. If you choose Disabled, the policy will not enforce compliance (useful, for example, as a second assignment to ignore a subset of non-compliant resources in a single resource group).'
    }

    Resource 'Microsoft.Storage/storageAccounts' {

        Require 'sku.name is like *ZRS' {
            Field sku.name | Must -BeLike '*ZRS'
        }

        Require 'kind is not Storage' {
            Field kind | Must -Not -Be 'Storage' -IfPresent
        }
    }

    Effect (Param Effect)
}

Source: built-in-policies/policyDefinitions/Resilience/Storage_storageAccounts_ZoneRedundant_Audit.json in Azure/azure-policy, under the MIT licence.