Bylaw

Gallery › Resilience › Azure built-in policies

[Preview]: Public IP addresses should be Zone Resilient

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

Public IP addresses can be configured to be either Zone Aligned, Zone Redundant, or neither. Public IP addresses that are regional, with exactly one entry in their zones array are considered Zone Aligned. In contrast, Public IP addresses that are regional, with 3 or more entries in their zones array are recognized as Zone Redundant. This policy helps identify and enforce these resilience configurations.

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

Azure Policy JSONNetwork_publicipaddresses_ZoneResilient_Audit.json · 117 lines
{
  "properties": {
    "displayName": "[Preview]: Public IP addresses should be Zone Resilient",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "Public IP addresses can be configured to be either Zone Aligned, Zone Redundant, or neither. Public IP addresses that are regional, with exactly one entry in their zones array are considered Zone Aligned. In contrast, Public IP addresses that are regional, with 3 or more entries in their zones array are recognized as Zone Redundant. This policy helps identify and enforce these resilience configurations.",
    "metadata": {
      "category": "Resilience",
      "version": "1.1.0-preview",
      "preview": true
    },
    "version": "1.1.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"
      },
      "allow": {
        "type": "String",
        "metadata": {
          "displayName": "Allowed Zone Configurations",
          "description": "This parameter lets you choose what type of Zone Resilience you want to allow. Aligned will identify any resources that are not configured as Zone Aligned as non-compliant resources. Redundant will identify any resources that are not configured to be Zone Redundant as non-compliant resources. Both (default), will identify any resource configurations that are not Zone Aligned or Zone Redundant as non-compliant resources."
        },
        "allowedValues": [
          "Both",
          "Redundant",
          "Aligned"
        ],
        "defaultValue": "Both"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Network/publicipaddresses"
          },
          {
            "field": "Microsoft.Network/publicIPAddresses/sku.tier",
            "equals": "Regional"
          },
          {
            "anyOf": [
              {
                "allOf": [
                  {
                    "value": "[parameters('allow')]",
                    "equals": "Both"
                  },
                  {
                    "count": {
                      "field": "Microsoft.Network/publicIPAddresses/zones[*]"
                    },
                    "less": 3
                  },
                  {
                    "count": {
                      "field": "Microsoft.Network/publicIPAddresses/zones[*]"
                    },
                    "notEquals": 1
                  }
                ]
              },
              {
                "allOf": [
                  {
                    "value": "[parameters('allow')]",
                    "equals": "Redundant"
                  },
                  {
                    "count": {
                      "field": "Microsoft.Network/publicIPAddresses/zones[*]"
                    },
                    "less": 3
                  }
                ]
              },
              {
                "allOf": [
                  {
                    "value": "[parameters('allow')]",
                    "equals": "Aligned"
                  },
                  {
                    "count": {
                      "field": "Microsoft.Network/publicIPAddresses/zones[*]"
                    },
                    "notEquals": 1
                  }
                ]
              }
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.1.0-PREVIEW",
      "1.0.0-PREVIEW"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/682e4ab9-59fe-4871-9839-265b54c568c4",
  "name": "682e4ab9-59fe-4871-9839-265b54c568c4"
}
Bylaw682e4ab9-59fe-4871-9839-265b54c568c4.bylaw.ps1 · 57 lines
# Converted from Network_publicipaddresses_ZoneResilient_Audit.json by ConvertTo-Bylaw.
Policy '682e4ab9-59fe-4871-9839-265b54c568c4' {

    Properties @{
        DisplayName   = '[Preview]: Public IP addresses should be Zone Resilient'
        Description   = 'Public IP addresses can be configured to be either Zone Aligned, Zone Redundant, or neither. Public IP addresses that are regional, with exactly one entry in their zones array are considered Zone Aligned. In contrast, Public IP addresses that are regional, with 3 or more entries in their zones array are recognized as Zone Redundant. This policy helps identify and enforce these resilience configurations.'
        Category      = 'Resilience'
        Version       = '1.1.0-preview'
        Preview       = $true
        PolicyVersion = '1.1.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).'
    }
    Parameter Allow @{
        AllowedValues = @('Both', 'Redundant', 'Aligned')
        Default       = 'Both'
        DisplayName   = 'Allowed Zone Configurations'
        Description   = 'This parameter lets you choose what type of Zone Resilience you want to allow. Aligned will identify any resources that are not configured as Zone Aligned as non-compliant resources. Redundant will identify any resources that are not configured to be Zone Redundant as non-compliant resources. Both (default), will identify any resource configurations that are not Zone Aligned or Zone Redundant as non-compliant resources.'
    }

    Resource 'Microsoft.Network/publicipaddresses' {

        When {
            Field sku.tier | Must -Be 'Regional'
        }

        Require 'zones is as required' {
            AnyOf {
                Param Allow | Must -Not -Be 'Both'
                Count 'zones[*]' | Must -BeGreaterOrEqual 3
                Count 'zones[*]' | Must -Be 1
            }
        }

        Require 'zones is as required' {
            AnyOf {
                Param Allow | Must -Not -Be 'Redundant'
                Count 'zones[*]' | Must -BeGreaterOrEqual 3
            }
        }

        Require 'zones is as required' {
            AnyOf {
                Param Allow | Must -Not -Be 'Aligned'
                Count 'zones[*]' | Must -Be 1
            }
        }
    }

    Effect (Param Effect)
}

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