Gallery › Network › Azure Community Policy
Newly created subnets will be assigned a Route Table
Doesn't convert yet Policy Append Audit Deny Disabled Mode All Version 1.0.0
This policy applies a specific Route Table to every newly created Subnet. This Policy will look for the existence of a keyword in a subnet name to apply the Policy. This policy must partner with the policy 'append-route-table-to-subnet-during-vnet-creation-based-on-naming-convention' in order to fully work. Additionally this policy is parameterized to be able to target all regions where a route table exists.
ConvertTo-Bylaw can't convert this policy yet:
- BYL6003 The converted file doesn't compile, which is a ConvertTo-Bylaw bug: BYL3072: Effect parameter 'Effect' of an Append policy allows 'Deny'. Allowed values: Append, Disabled. BYL3072: Effect parameter 'Effect' of an Append policy allows 'Audit'. Allowed values: Append, Disabled.
Azure Policy JSONazurepolicy.json · 79 lines
{
"name": "ad0328f0-915c-422f-98be-bc8d60159827",
"type": "Microsoft.Authorization/policyDefinitions",
"properties": {
"displayName": "Newly created subnets will be assigned a Route Table",
"description": "This policy applies a specific Route Table to every newly created Subnet. This Policy will look for the existence of a keyword in a subnet name to apply the Policy. This policy must partner with the policy 'append-route-table-to-subnet-during-vnet-creation-based-on-naming-convention' in order to fully work. Additionally this policy is parameterized to be able to target all regions where a route table exists.",
"metadata": {
"version": "1.0.0",
"category": "Network"
},
"mode": "All",
"parameters": {
"targetedNamingConvention": {
"type": "String",
"metadata": {
"displayName": "Targeted Subnet Naming Convention",
"description": "This determines the keyword in the subnet name that will be used to trigger the Policy"
}
},
"resourceGroupNamingConvention": {
"type": "String",
"metadata": {
"displayName": "Route Table Resource Groups Naming Convention",
"description": "This is to help locate the regions route table. This concats the flagged resources region with this value. In example, if you defined this param as '-example': eastus-example."
}
},
"routeTableNamingConvention": {
"type": "String",
"metadata": {
"displayName": "Route Table Naming Convention",
"description": "This is the name for your route table. This assumes the route tables in all regions have the same name. "
}
},
"effect": {
"type": "String",
"metadata": {
"displayName": "Effect",
"description": "Append, Deny, Audit or Disable the execution of the Policy"
},
"allowedValues": [
"Append",
"Deny",
"Audit",
"Disabled"
],
"defaultValue": "Append"
}
},
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Network/virtualNetworks/subnets"
},
{
"not": {
"field": "Microsoft.Network/virtualNetworks/subnets/routeTable.id",
"equals": "[concat(subscription().id, '/resourceGroups/', resourcegroup().location, parameters('resourceGroupNamingConvention'), '/providers/Microsoft.Network/routeTables/', parameters('routeTableNamingConvention'))]"
}
},
{
"field": "name",
"contains": "[parameters('targetedNamingConvention')]"
}
]
},
"then": {
"effect": "[parameters('effect')]",
"details": [
{
"field": "Microsoft.Network/virtualNetworks/subnets/routeTable.id",
"value": "[concat(subscription().id, '/resourceGroups/', resourcegroup().location, parameters('resourceGroupNamingConvention'), '/providers/Microsoft.Network/routeTables/', parameters('routeTableNamingConvention'))]"
}
]
}
}
}
}Source: policyDefinitions/Network/newly-created-subnets-will-be-assigned-a-route-table/azurepolicy.json in Azure/Community-Policy, under the MIT licence.
Bylaw