I have attempted this using address prefix ranges, as we are aware of the address spaces used within the 'corp' VNETs. However, we do not have information on the ranges for the 'online' VNETs. Therefore, we can only check the ranges for the 'corp' VNETs in the condition
"parameters": {
"corpVNetAddressPrefixes": {
"type": "Array",
"metadata": {
"displayName": "Corp VNet Address Prefixes",
"description": "The list of Corp Subscription VNets address prefixes."
},
"defaultValue": [
"17.0.0.0/24"
]
}
},
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Network/virtualNetworks/virtualNetworkPeerings"
},
{
"field": "Microsoft.Network/virtualNetworks/virtualNetworkPeerings/remoteVirtualNetwork.id",
"notcontains": "[subscription().id]"
},
{
"anyOf": [
{
"field": "Microsoft.Network/virtualNetworks/virtualNetworkPeerings/remoteVirtualNetworkAddressSpace.addressPrefixes[*]",
"in": "[parameters('corpVNetAddressPrefixes')]"
},
{
"field": "Microsoft.Network/virtualNetworks/virtualNetworkPeerings/remoteAddressSpace.addressPrefixes[*]",
"in": "[parameters('corpVNetAddressPrefixes')]"
},
{
"field": "Microsoft.Network/virtualNetworks/virtualNetworkPeerings/localVirtualNetworkAddressSpace.addressPrefixes[*]",
"in": "[parameters('corpVNetAddressPrefixes')]"
},
{
"field": "Microsoft.Network/virtualNetworks/virtualNetworkPeerings/localAddressSpace.addressPrefixes[*]",
"in": "[parameters('corpVNetAddressPrefixes')]"
}
]
}
]
},
"then": {
"effect": "deny"
}
however this solution working for one of the peering resource, but not for other (whenever we create a peering it creates two vnet-peering resources one in local VNet and other in selected RemoteVNet)
The issue here is the alias localVirtualNetworkAddressSpace.addressPrefixes[*] & virtualNetworkPeerings/localAddressSpace.addressPrefixes[*] is not working here in the policy rule and even not showing in resource json. due to which { "field": "Microsoft.Network/virtualNetworks/virtualNetworkPeerings/localVirtualNetworkAddressSpace.addressPrefixes[*]", "in": "[parameters('corpVNetAddressPrefixes')]" } this condition is not working as expected
I have also tried with subscription tags but unfortunately we do not have remoteVirtualNtwork.tags alias available(can be requested raising a support ticket)


