Bylaw

Gallery › Network › Azure Community Policy

Audit unattached static Public IPs

Converted Policy Audit Disabled Mode All Version 1.0.0

Static Public IPs incur cost even when not in use. This Policy will help you detect the existence of unattached static Public IPs in the effort to help drive down cost.

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

Azure Policy JSONazurepolicy.json · 48 lines
{
  "name": "0053d708-522e-4a5a-bd67-367fb589ddbb",
  "type": "Microsoft.Authorization/policyDefinitions",
  "properties": {
    "displayName": "Audit unattached static Public IPs",
    "description": "Static Public IPs incur cost even when not in use. This Policy will help you detect the existence of unattached static Public IPs in the effort to help drive down cost.",
    "metadata": {
      "version": "1.0.0",
      "category": "Network"
    },
    "mode": "All",
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Audit or Disabled the execution of the Policy"
        },
        "allowedValues": [
          "Audit",
          "Disabled"
        ],
        "defaultValue": "Audit"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Network/publicIPAddresses"
          },
          {
            "field": "Microsoft.Network/publicIPAddresses/publicIPAllocationMethod",
            "equals": "Static"
          },
          {
            "field": "Microsoft.Network/publicIPAddresses/ipConfiguration",
            "exists": false
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    }
  }
}
Bylaw0053d708-522e-4a5a-bd67-367fb589ddbb.bylaw.ps1 · 31 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy '0053d708-522e-4a5a-bd67-367fb589ddbb' {

    Properties @{
        DisplayName = 'Audit unattached static Public IPs'
        Description = 'Static Public IPs incur cost even when not in use. This Policy will help you detect the existence of unattached static Public IPs in the effort to help drive down cost.'
        Version     = '1.0.0'
        Category    = 'Network'
        Mode        = 'All'
    }

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

    Resource 'Microsoft.Network/publicIPAddresses' {

        When {
            Field publicIPAllocationMethod | Must -Be 'Static'
        }

        Require 'ipConfiguration exists' {
            Field ipConfiguration | Must -Exist
        }
    }

    Effect (Param Effect)
}

Source: policyDefinitions/Network/audit-unattached-static-public-ips/azurepolicy.json in Azure/Community-Policy, under the MIT licence.