Bylaw

Gallery › Network › Azure built-in policies

Public IPs and Public IP prefixes should have FirstPartyUsage tag

Converted Policy Audit Deny Disabled Mode Indexed Version 1.1.0

Ensure all Public IP addresses and Public IP Prefixes have a FirstPartyUsage tag.

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

Azure Policy JSONPublicIPWithFPUOnly_Audit.json · 91 lines
{
  "properties": {
    "displayName": "Public IPs and Public IP prefixes should have FirstPartyUsage tag",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "Ensure all Public IP addresses and Public IP Prefixes have a FirstPartyUsage tag.",
    "metadata": {
      "version": "1.1.0",
      "category": "Network"
    },
    "version": "1.1.0",
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        },
        "allowedValues": [
          "Audit",
          "Deny",
          "Disabled"
        ],
        "defaultValue": "Audit"
      }
    },
    "policyRule": {
      "if": {
        "anyOf": [
          {
            "allOf": [
              {
                "field": "type",
                "equals": "Microsoft.Network/publicIPAddresses"
              },
              {
                "anyOf": [
                  {
                    "field": "Microsoft.Network/publicIPAddresses/publicIPPrefix.id",
                    "exists": "false"
                  },
                  {
                    "field": "Microsoft.Network/publicIPAddresses/publicIPPrefix.id",
                    "equals": ""
                  }
                ]
              },
              {
                "count": {
                  "field": "Microsoft.Network/publicIPAddresses/ipTags[*]",
                  "where": {
                    "field": "Microsoft.Network/publicIPAddresses/ipTags[*].ipTagType",
                    "equals": "FirstPartyUsage"
                  }
                },
                "less": 1
              }
            ]
          },
          {
            "allOf": [
              {
                "field": "type",
                "equals": "Microsoft.Network/publicIPPrefixes"
              },
              {
                "count": {
                  "field": "Microsoft.Network/publicIPPrefixes/ipTags[*]",
                  "where": {
                    "field": "Microsoft.Network/publicIPPrefixes/ipTags[*].ipTagType",
                    "equals": "FirstPartyUsage"
                  }
                },
                "less": 1
              }
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.1.0",
      "1.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/fe8a9af4-a003-4c7d-b7a4-b9808310c4f8",
  "name": "fe8a9af4-a003-4c7d-b7a4-b9808310c4f8"
}
Bylawfe8a9af4-a003-4c7d-b7a4-b9808310c4f8.bylaw.ps1 · 43 lines
# Converted from PublicIPWithFPUOnly_Audit.json by ConvertTo-Bylaw.
Policy 'fe8a9af4-a003-4c7d-b7a4-b9808310c4f8' {

    Properties @{
        DisplayName   = 'Public IPs and Public IP prefixes should have FirstPartyUsage tag'
        Description   = 'Ensure all Public IP addresses and Public IP Prefixes have a FirstPartyUsage tag.'
        Version       = '1.1.0'
        Category      = 'Network'
        PolicyVersion = '1.1.0'
        Mode          = 'Indexed'
    }

    Parameter Effect @{
        AllowedValues = @('Audit', 'Deny', 'Disabled')
        Default       = 'Audit'
        DisplayName   = 'Effect'
        Description   = 'Enable or disable the execution of the policy'
    }

    Resource * {

        Require 'type, publicIPPrefix.id, ipTags and 1 more are as required' {
            AnyOf {
                Field type | Must -Not -Be 'Microsoft.Network/publicIPAddresses' -IfPresent
                Field 'Microsoft.Network/publicIPAddresses/publicIPPrefix.id' | Must -Not -Be ''
                Count 'Microsoft.Network/publicIPAddresses/ipTags[*]' -Where {
                    Field ipTagType | Must -Be 'FirstPartyUsage'
                } | Must -BeGreaterOrEqual 1
            }
        }

        Require 'type, ipTags and ipTagType are as required' {
            AnyOf {
                Field type | Must -Not -Be 'Microsoft.Network/publicIPPrefixes' -IfPresent
                Count 'Microsoft.Network/publicIPPrefixes/ipTags[*]' -Where {
                    Field ipTagType | Must -Be 'FirstPartyUsage'
                } | Must -BeGreaterOrEqual 1
            }
        }
    }

    Effect (Param Effect)
}

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