Bylaw

Gallery › Network › Azure Community Policy

Allowed Peering Location for Express Route

Converted Policy Audit Deny Disabled Mode All Version 1.0.0

This policy enables you to specify a set of allowed peering location for express route

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

Azure Policy JSONazurepolicy.json · 55 lines
{
  "name": "9f8caf61-95c2-42c8-b5da-ab71ed6b0700",
  "type": "Microsoft.Authorization/policyDefinitions",
  "properties": {
    "displayName": "Allowed Peering Location for Express Route",
    "description": "This policy enables you to specify a set of allowed peering location for express route",
    "metadata": {
      "version": "1.0.0",
      "category": "Network"
    },
    "mode": "All",
    "parameters": {
      "listOfLocations": {
        "type": "Array",
        "metadata": {
          "description": "The list of peering locations that can be specified for express route.",
          "displayName": "Allowed Peering Locations",
          "strongType": "Location"
        }
      },
      "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/expressRouteCircuits"
          },
          {
            "not": {
              "field": "Microsoft.Network/expressRouteCircuits/serviceProviderProperties.peeringLocation",
              "in": "[parameters('listOfLocations')]"
            }
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    }
  }
}
Bylaw9f8caf61-95c2-42c8-b5da-ab71ed6b0700.bylaw.ps1 · 33 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy '9f8caf61-95c2-42c8-b5da-ab71ed6b0700' {

    Properties @{
        DisplayName = 'Allowed Peering Location for Express Route'
        Description = 'This policy enables you to specify a set of allowed peering location for express route'
        Version     = '1.0.0'
        Category    = 'Network'
        Mode        = 'All'
    }

    Parameter ListOfLocations @{
        Type        = 'Array'
        DisplayName = 'Allowed Peering Locations'
        Description = 'The list of peering locations that can be specified for express route.'
        Metadata    = [ordered]@{ strongType = 'Location' }
    }
    Parameter Effect @{
        AllowedValues = @('Deny', 'Audit', 'Disabled')
        Default       = 'Audit'
        DisplayName   = 'Effect'
        Description   = 'Deny, Audit or Disabled the execution of the Policy'
    }

    Resource 'Microsoft.Network/expressRouteCircuits' {

        Require 'serviceProviderProperties.peeringLocation is one of the ListOfLocations parameter' {
            Field serviceProviderProperties.peeringLocation | Must -BeIn (Param ListOfLocations)
        }
    }

    Effect (Param Effect)
}

Source: policyDefinitions/Network/allowed-peering-location-for-express-route/azurepolicy.json in Azure/Community-Policy, under the MIT licence.