Bylaw

Gallery › Network › Azure Community Policy

No network peering to ER network

Converted Policy Audit Deny Disabled Mode All Version 1.0.0

No network peering can be associated to networks in network in a resource group containing central managed network infrastructure.

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

Azure Policy JSONazurepolicy.json · 53 lines
{
  "name": "b2a0ab0c-4bc0-4157-a662-47d23188085a",
  "type": "Microsoft.Authorization/policyDefinitions",
  "properties": {
    "displayName": "No network peering to ER network",
    "description": "No network peering can be associated to networks in network in a resource group containing central managed network infrastructure.",
    "metadata": {
      "version": "1.0.0",
      "category": "Network"
    },
    "mode": "All",
    "parameters": {
      "resourceGroupName": {
        "type": "String",
        "metadata": {
          "description": "Name of the resource group with ER Network",
          "displayName": "ER Network Resource Group Name",
          "strongType": "ExistingResourceGroups"
        }
      },
      "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/virtualNetworks/virtualNetworkPeerings"
          },
          {
            "field": "Microsoft.Network/virtualNetworks/virtualNetworkPeerings/remoteVirtualNetwork.id",
            "contains": "[concat('resourceGroups/',parameters('resourceGroupName'))]"
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    }
  }
}
Bylawb2a0ab0c-4bc0-4157-a662-47d23188085a.bylaw.ps1 · 33 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy 'b2a0ab0c-4bc0-4157-a662-47d23188085a' {

    Properties @{
        DisplayName = 'No network peering to ER network'
        Description = 'No network peering can be associated to networks in network in a resource group containing central managed network infrastructure.'
        Version     = '1.0.0'
        Category    = 'Network'
        Mode        = 'All'
    }

    Parameter ResourceGroupName @{
        Type        = 'String'
        DisplayName = 'ER Network Resource Group Name'
        Description = 'Name of the resource group with ER Network'
        Metadata    = [ordered]@{ strongType = 'ExistingResourceGroups' }
    }
    Parameter Effect @{
        AllowedValues = @('Deny', 'Audit', 'Disabled')
        Default       = 'Audit'
        DisplayName   = 'Effect'
        Description   = 'Deny, Audit or Disabled the execution of the Policy'
    }

    Resource 'Microsoft.Network/virtualNetworks/virtualNetworkPeerings' {

        Require 'remoteVirtualNetwork.id is as required' {
            Field remoteVirtualNetwork.id | Must -Not -ContainText (Arm '[concat(''resourceGroups/'',parameters(''resourceGroupName''))]') -IfPresent
        }
    }

    Effect (Param Effect)
}

Source: policyDefinitions/Network/no-network-peering-to-er-network/azurepolicy.json in Azure/Community-Policy, under the MIT licence.