Bylaw

Gallery › Network › Azure Community Policy

require-specific-route-on-udr

Converted Policy Audit Deny Disabled Mode All Version 1.0.0

need to add description

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

Azure Policy JSONazurepolicy.json · 91 lines
{
  "name": "e692ec51-5975-4243-84c8-b6a6aa5affb5",
  "type": "Microsoft.Authorization/policyDefinitions",
  "properties": {
    "displayName": "require-specific-route-on-udr",
    "description": "need to add description",
    "metadata": {
      "version": "1.0.0",
      "category": "Network"
    },
    "mode": "All",
    "parameters": {
      "addressPrefix": {
        "type": "string",
        "metadata": {
          "description": "The destination IP address range in CIDR notation that this Policy checks for within the UDR. Example: 0.0.0.0/0 to check for the presence of a default route.",
          "displayName": "Address Prefix"
        }
      },
      "nextHopType": {
        "type": "string",
        "metadata": {
          "description": "The next hope type that the policy checks for within the inspected route. The value can be Virtual Network, Virtual Network Gateway, Internet, Virtual Appliance, or None.",
          "displayName": "Next Hop Type"
        },
        "allowedValues": [
          "VnetLocal",
          "VirtualNetworkGateway",
          "Internet",
          "VirtualAppliance",
          "None"
        ]
      },
      "nextHopIpAddress": {
        "type": "string",
        "metadata": {
          "description": "The IP address packets should be forwarded to.",
          "displayName": "Next Hop IP Address"
        }
      },
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Deny, Audit or Disabled the execution of the Policy"
        },
        "allowedValues": [
          "Deny",
          "Audit",
          "Disabled"
        ],
        "defaultValue": "Audit"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Network/routeTables"
          },
          {
            "count": {
              "field": "Microsoft.Network/routeTables/routes[*]",
              "where": {
                "allOf": [
                  {
                    "field": "Microsoft.Network/routeTables/routes[*].addressPrefix",
                    "equals": "[parameters('addressPrefix')]"
                  },
                  {
                    "field": "Microsoft.Network/routeTables/routes[*].nextHopType",
                    "equals": "[parameters('nextHopType')]"
                  },
                  {
                    "field": "Microsoft.Network/routeTables/routes[*].nextHopIpAddress",
                    "equals": "[parameters('nextHopIpAddress')]"
                  }
                ]
              }
            },
            "less": 1
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    }
  }
}
Bylawe692ec51-5975-4243-84c8-b6a6aa5affb5.bylaw.ps1 · 47 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy 'e692ec51-5975-4243-84c8-b6a6aa5affb5' {

    Properties @{
        DisplayName = 'require-specific-route-on-udr'
        Description = 'need to add description'
        Version     = '1.0.0'
        Category    = 'Network'
        Mode        = 'All'
    }

    Parameter AddressPrefix @{
        Type        = 'string'
        DisplayName = 'Address Prefix'
        Description = 'The destination IP address range in CIDR notation that this Policy checks for within the UDR. Example: 0.0.0.0/0 to check for the presence of a default route.'
    }
    Parameter NextHopType @{
        Type          = 'string'
        AllowedValues = @('VnetLocal', 'VirtualNetworkGateway', 'Internet', 'VirtualAppliance', 'None')
        DisplayName   = 'Next Hop Type'
        Description   = 'The next hope type that the policy checks for within the inspected route. The value can be Virtual Network, Virtual Network Gateway, Internet, Virtual Appliance, or None.'
    }
    Parameter NextHopIpAddress @{
        Type        = 'string'
        DisplayName = 'Next Hop IP Address'
        Description = 'The IP address packets should be forwarded to.'
    }
    Parameter Effect @{
        AllowedValues = @('Deny', 'Audit', 'Disabled')
        Default       = 'Audit'
        DisplayName   = 'Effect'
        Description   = 'Deny, Audit or Disabled the execution of the Policy'
    }

    Resource 'Microsoft.Network/routeTables' {

        Require 'routes, addressPrefix, nextHopType and 1 more are as required' {
            Count 'routes[*]' -Where {
                Field addressPrefix | Must -Be (Param AddressPrefix)
                Field nextHopType | Must -Be (Param NextHopType)
                Field nextHopIpAddress | Must -Be (Param NextHopIpAddress)
            } | Must -BeGreaterOrEqual 1
        }
    }

    Effect (Param Effect)
}

Source: policyDefinitions/Network/require-specific-route-on-udr/azurepolicy.json in Azure/Community-Policy, under the MIT licence.