Gallery › Network › Azure Community Policy
Deny changing Address Space of a Virtual Network
Converted Policy Audit Deny Disabled Mode All Version 1.0.0
This Policy will prevent users from changing the Address Space on a VNet
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
Azure Policy JSONazurepolicy.json · 60 lines
{
"name": "c44b6bd8-0754-4762-8c1e-20ca62ac9df5",
"type": "Microsoft.Authorization/policyDefinitions",
"properties": {
"displayName": "Deny changing Address Space of a Virtual Network",
"description": "This Policy will prevent users from changing the Address Space on a VNet",
"metadata": {
"version": "1.0.0",
"category": "Network"
},
"mode": "All",
"parameters": {
"addressSpaceSettings": {
"type": "array",
"metadata": {
"displayname": "Enforced Address Space Settings",
"description": "Users will be unable to change the address space on a VNet from the values defined in this array."
}
},
"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"
},
{
"anyOf": [
{
"value": "[if(empty(field('Microsoft.Network/virtualNetworks/addressSpace.addressPrefixes')), bool('false'), equals(length(intersection(parameters('addressSpaceSettings'), field('Microsoft.Network/virtualNetworks/addressSpace.addressPrefixes'))), length(parameters('addressSpaceSettings'))))]",
"equals": false
},
{
"value": "[if(empty(field('Microsoft.Network/virtualNetworks/addressSpace.addressPrefixes')), bool('false'), equals(length(field('Microsoft.Network/virtualNetworks/addressSpace.addressPrefixes')),length(parameters('addressSpaceSettings'))))]",
"equals": false
}
]
}
]
},
"then": {
"effect": "[parameters('effect')]"
}
}
}
}Bylawc44b6bd8-0754-4762-8c1e-20ca62ac9df5.bylaw.ps1 · 36 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy 'c44b6bd8-0754-4762-8c1e-20ca62ac9df5' {
Properties @{
DisplayName = 'Deny changing Address Space of a Virtual Network'
Description = 'This Policy will prevent users from changing the Address Space on a VNet'
Version = '1.0.0'
Category = 'Network'
Mode = 'All'
}
Parameter AddressSpaceSettings @{
Type = 'array'
DisplayName = 'Enforced Address Space Settings'
Description = 'Users will be unable to change the address space on a VNet from the values defined in this array.'
}
Parameter Effect @{
AllowedValues = @('Deny', 'Audit', 'Disabled')
Default = 'Audit'
DisplayName = 'Effect'
Description = 'Deny, Audit or Disabled the execution of the Policy'
}
Resource 'Microsoft.Network/virtualNetworks' {
Require 'addressSpace.addressPrefixes is as required' {
Arm '[if(empty(field(''Microsoft.Network/virtualNetworks/addressSpace.addressPrefixes'')), bool(''false''), equals(length(intersection(parameters(''addressSpaceSettings''), field(''Microsoft.Network/virtualNetworks/addressSpace.addressPrefixes''))), length(parameters(''addressSpaceSettings''))))]' | Must -Not -Be $false
}
Require 'addressSpace.addressPrefixes is as required' {
Arm '[if(empty(field(''Microsoft.Network/virtualNetworks/addressSpace.addressPrefixes'')), bool(''false''), equals(length(field(''Microsoft.Network/virtualNetworks/addressSpace.addressPrefixes'')),length(parameters(''addressSpaceSettings''))))]' | Must -Not -Be $false
}
}
Effect (Param Effect)
}Source: policyDefinitions/Network/deny-changing-address-space-of-a-virtual-network/azurepolicy.json in Azure/Community-Policy, under the MIT licence.
Bylaw