Gallery › Network › Azure Community Policy
Deny VNet peering removal
Converted Policy DenyAction Disabled Mode All Version 1.0.0
This Policy will deny the deletion of VNets peerings with a specified name.
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
Azure Policy JSONazurepolicy.json · 57 lines
{
"name": "6f194805-9450-4e29-bd6a-9bc370329126",
"type": "Microsoft.Authorization/policyDefinitions",
"properties": {
"displayName": "Deny VNet peering removal",
"description": "This Policy will deny the deletion of VNets peerings with a specified name.",
"metadata": {
"version": "1.0.0",
"category": "Network"
},
"mode": "All",
"parameters": {
"effect": {
"type": "String",
"metadata": {
"displayName": "Effect",
"description": "DenyAction or Disabled the execution of the Policy"
},
"allowedValues": [
"DenyAction",
"Disabled"
],
"defaultValue": "DenyAction"
},
"peeringName": {
"type": "String",
"metadata": {
"displayName": "VNet peering name",
"description": "Name of the VNet peering that is not allowed to be removed"
},
"defaultValue": "Spoke-to-Hub"
}
},
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Network/virtualNetworks/virtualNetworkPeerings"
},
{
"field": "name",
"equals": "[parameters('peeringName')]"
}
]
},
"then": {
"effect": "[parameters('effect')]",
"details": {
"actionNames": [
"delete"
]
}
}
}
}
}Bylaw6f194805-9450-4e29-bd6a-9bc370329126.bylaw.ps1 · 32 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy '6f194805-9450-4e29-bd6a-9bc370329126' {
Properties @{
DisplayName = 'Deny VNet peering removal'
Description = 'This Policy will deny the deletion of VNets peerings with a specified name.'
Version = '1.0.0'
Category = 'Network'
Mode = 'All'
}
Parameter Effect @{
AllowedValues = @('DenyAction', 'Disabled')
Default = 'DenyAction'
DisplayName = 'Effect'
Description = 'DenyAction or Disabled the execution of the Policy'
}
Parameter PeeringName @{
Default = 'Spoke-to-Hub'
DisplayName = 'VNet peering name'
Description = 'Name of the VNet peering that is not allowed to be removed'
}
Resource 'Microsoft.Network/virtualNetworks/virtualNetworkPeerings' {
Require 'name is not the PeeringName parameter' {
Field name | Must -Not -Be (Param PeeringName) -IfPresent
}
}
DenyAction Delete -Effect (Param Effect)
}Source: policyDefinitions/Network/vnet-peering-deny-removal/azurepolicy.json in Azure/Community-Policy, under the MIT licence.
Bylaw