I had a go at this but haven't tested.
Note: removed the condition referencing "Microsoft.Resources/subscriptions/resourceGroups" because the existing definition already references "Microsoft.Network/virtualNetworks" and policy validation complains if you have conditions for more than 1 resources type specified in the same definition.
Question: are tag values also required for the exclusion, not just the RG name?
{
"mode": "All",
"parameters": {
"tagName": {
"type": "String",
"metadata": {
"displayName": "Tag name",
"description": "Name of the tag"
}
}
},
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Network/virtualNetworks"
},
{
"field": "Microsoft.Network/virtualNetworks/addressSpace.addressPrefixes[*]",
"notContains": "11.22.33"
},
{
"allOf": [
{
"field": "[concat('tags[', parameters('tagName'), ']')]",
"exists": "false"
},
{
"value": "[startsWith(field('name'), 'MC_')]",
"notEquals": "true"
}
]
}
]
},
"then": {
"effect": "deny"
}
}
}