Gallery › Network › Azure Community Policy
Enforce a route table on every subnet
Converted Policy Audit Deny Disabled Mode All Version 1.0.0
This policy enforces a specific Route Table on every subnet
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
Azure Policy JSONazurepolicy.json · 72 lines
{
"name": "112dff39-d7a2-4d2a-9885-0c301725ce30",
"type": "Microsoft.Authorization/policyDefinitions",
"properties": {
"displayName": "Enforce a route table on every subnet",
"description": "This policy enforces a specific Route Table on every subnet",
"metadata": {
"version": "1.0.0",
"category": "Network"
},
"mode": "All",
"parameters": {
"rtId": {
"type": "String",
"metadata": {
"description": "Resource Id of the route table. example:/subscriptions/yourSubscription/resourceGroups/yourResourceGroup/providers/Microsoft.Network/routeTables/aTable",
"displayName": "Route table Id"
}
},
"effect": {
"type": "String",
"metadata": {
"displayName": "Effect",
"description": "Deny, Audit or Disabled the execution of the Policy"
},
"allowedValues": [
"Deny",
"Audit",
"Disabled"
],
"defaultValue": "Audit"
}
},
"policyRule": {
"if": {
"anyOf": [
{
"allOf": [
{
"field": "type",
"equals": "Microsoft.Network/virtualNetworks"
},
{
"not": {
"field": "Microsoft.Network/virtualNetworks/subnets[*].routeTable.id",
"equals": "[parameters('rtId')]"
}
}
]
},
{
"allOf": [
{
"field": "type",
"equals": "Microsoft.Network/virtualNetworks/subnets"
},
{
"not": {
"field": "Microsoft.Network/virtualNetworks/subnets/routeTable.id",
"equals": "[parameters('rtId')]"
}
}
]
}
]
},
"then": {
"effect": "[parameters('effect')]"
}
}
}
}Bylaw112dff39-d7a2-4d2a-9885-0c301725ce30.bylaw.ps1 · 47 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy '112dff39-d7a2-4d2a-9885-0c301725ce30' {
Properties @{
DisplayName = 'Enforce a route table on every subnet'
Description = 'This policy enforces a specific Route Table on every subnet'
Version = '1.0.0'
Category = 'Network'
Mode = 'All'
}
Parameter RtId @{
Type = 'String'
DisplayName = 'Route table Id'
Description = 'Resource Id of the route table. example:/subscriptions/yourSubscription/resourceGroups/yourResourceGroup/providers/Microsoft.Network/routeTables/aTable'
}
Parameter Effect @{
AllowedValues = @('Deny', 'Audit', 'Disabled')
Default = 'Audit'
DisplayName = 'Effect'
Description = 'Deny, Audit or Disabled the execution of the Policy'
}
Resource * {
Require 'type, subnets and routeTable.id are as required' {
AnyOf {
Field type | Must -Not -Be 'Microsoft.Network/virtualNetworks' -IfPresent
AllOf {
Field 'Microsoft.Network/virtualNetworks/subnets' | Must -Exist
Each 'Microsoft.Network/virtualNetworks/subnets[*]' {
Field routeTable.id | Must -Be (Param RtId) -Strict
}
}
}
}
Require 'type and routeTable.id are as required' {
AnyOf {
Field type | Must -Not -Be 'Microsoft.Network/virtualNetworks/subnets' -IfPresent
Field 'Microsoft.Network/virtualNetworks/subnets/routeTable.id' | Must -Be (Param RtId)
}
}
}
Effect (Param Effect)
}Source: policyDefinitions/Network/enforce-a-route-table-on-every-subnet/azurepolicy.json in Azure/Community-Policy, under the MIT licence.
Bylaw