Bylaw

Gallery › Network › Azure Community Policy

Vnet peering disallowed outside subscription

Converted Policy Audit Deny Disabled Mode All Version 1.0.0

No network peering can be associated to networks outside the current subscription.

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

Azure Policy JSONazurepolicy.json · 45 lines
{
  "name": "02445760-2921-4076-a9b5-38ec91b3126f",
  "type": "Microsoft.Authorization/policyDefinitions",
  "properties": {
    "displayName": "Vnet peering disallowed outside subscription",
    "description": "No network peering can be associated to networks outside the current subscription.",
    "metadata": {
      "version": "1.0.0",
      "category": "Network"
    },
    "mode": "All",
    "parameters": {
      "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",
            "notcontains": "[subscription().id]"
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    }
  }
}
Bylaw02445760-2921-4076-a9b5-38ec91b3126f.bylaw.ps1 · 27 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy '02445760-2921-4076-a9b5-38ec91b3126f' {

    Properties @{
        DisplayName = 'Vnet peering disallowed outside subscription'
        Description = 'No network peering can be associated to networks outside the current subscription.'
        Version     = '1.0.0'
        Category    = 'Network'
        Mode        = 'All'
    }

    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 contains (Arm ''[subscription().id]'')' {
            Field remoteVirtualNetwork.id | Must -ContainText (Arm '[subscription().id]')
        }
    }

    Effect (Param Effect)
}

Source: policyDefinitions/Network/vnet-peering-disallowed-outside-subscription/azurepolicy.json in Azure/Community-Policy, under the MIT licence.