|
| 1 | +{ |
| 2 | + "$schema": "https://schema.management.azure.com/schemas/2019-08-01/managementGroupDeploymentTemplate.json#", |
| 3 | + "contentVersion": "1.0.0.0", |
| 4 | + "parameters": { |
| 5 | + "policyName": { |
| 6 | + "metadata": { |
| 7 | + "description": "Policy name" |
| 8 | + }, |
| 9 | + "type": "string", |
| 10 | + "defaultValue": "Policy-example" |
| 11 | + } |
| 12 | + }, |
| 13 | + "resources": [ |
| 14 | + { |
| 15 | + "name": "[parameters('policyName')]", |
| 16 | + "type": "Microsoft.Authorization/policyDefinitions", |
| 17 | + "apiVersion": "2021-06-01", |
| 18 | + "properties": { |
| 19 | + "policyType": "Custom", |
| 20 | + "mode": "Indexed", |
| 21 | + "displayName": "Deploy a route table with specific user defined routes", |
| 22 | + "description": "Deploys a route table with specific user defined routes when one does not exist. The route table deployed by the policy must be manually associated to subnet(s)", |
| 23 | + "metadata": { |
| 24 | + "version": "1.0.0", |
| 25 | + "category": "Network", |
| 26 | + "source": "https://github.com/Azure/Enterprise-Scale/", |
| 27 | + "alzCloudEnvironments": [ |
| 28 | + "AzureCloud", |
| 29 | + "AzureChinaCloud", |
| 30 | + "AzureUSGovernment" |
| 31 | + ] |
| 32 | + }, |
| 33 | + "parameters": { |
| 34 | + "effect": { |
| 35 | + "type": "String", |
| 36 | + "metadata": { |
| 37 | + "displayName": "Effect", |
| 38 | + "description": "Enable or disable the execution of the policy" |
| 39 | + }, |
| 40 | + "allowedValues": [ |
| 41 | + "DeployIfNotExists", |
| 42 | + "Disabled" |
| 43 | + ], |
| 44 | + "defaultValue": "DeployIfNotExists" |
| 45 | + }, |
| 46 | + "requiredRoutes": { |
| 47 | + "type": "Array", |
| 48 | + "metadata": { |
| 49 | + "displayName": "requiredRoutes", |
| 50 | + "description": "Routes that must exist in compliant route tables deployed by this policy" |
| 51 | + } |
| 52 | + }, |
| 53 | + "vnetRegion": { |
| 54 | + "type": "String", |
| 55 | + "metadata": { |
| 56 | + "displayName": "vnetRegion", |
| 57 | + "description": "Only VNets in this region will be evaluated against this policy" |
| 58 | + } |
| 59 | + }, |
| 60 | + "routeTableName": { |
| 61 | + "type": "String", |
| 62 | + "metadata": { |
| 63 | + "displayName": "routeTableName", |
| 64 | + "description": "Name of the route table automatically deployed by this policy" |
| 65 | + } |
| 66 | + }, |
| 67 | + "disableBgpPropagation": { |
| 68 | + "type": "Boolean", |
| 69 | + "metadata": { |
| 70 | + "displayName": "DisableBgpPropagation", |
| 71 | + "description": "Disable BGP Propagation" |
| 72 | + }, |
| 73 | + "defaultValue": false |
| 74 | + } |
| 75 | + }, |
| 76 | + "policyRule": { |
| 77 | + "if": { |
| 78 | + "allOf": [ |
| 79 | + { |
| 80 | + "field": "type", |
| 81 | + "equals": "Microsoft.Network/virtualNetworks" |
| 82 | + }, |
| 83 | + { |
| 84 | + "field": "location", |
| 85 | + "equals": "[[parameters('vnetRegion')]" |
| 86 | + } |
| 87 | + ] |
| 88 | + }, |
| 89 | + "then": { |
| 90 | + "effect": "[[parameters('effect')]", |
| 91 | + "details": { |
| 92 | + "type": "Microsoft.Network/routeTables", |
| 93 | + "existenceCondition": { |
| 94 | + "allOf": [ |
| 95 | + { |
| 96 | + "field": "name", |
| 97 | + "equals": "[[parameters('routeTableName')]" |
| 98 | + }, |
| 99 | + { |
| 100 | + "count": { |
| 101 | + "field": "Microsoft.Network/routeTables/routes[*]", |
| 102 | + "where": { |
| 103 | + "value": "[[concat(current('Microsoft.Network/routeTables/routes[*].addressPrefix'), ';', current('Microsoft.Network/routeTables/routes[*].nextHopType'), if(equals(toLower(current('Microsoft.Network/routeTables/routes[*].nextHopType')),'virtualappliance'), concat(';', current('Microsoft.Network/routeTables/routes[*].nextHopIpAddress')), ''))]", |
| 104 | + "in": "[[parameters('requiredRoutes')]" |
| 105 | + } |
| 106 | + }, |
| 107 | + "equals": "[[length(parameters('requiredRoutes'))]" |
| 108 | + } |
| 109 | + ] |
| 110 | + }, |
| 111 | + "roleDefinitionIds": [ |
| 112 | + "/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/roleDefinitions/00000000-0000-0000-0000-000000000000" |
| 113 | + ], |
| 114 | + "deployment": { |
| 115 | + "properties": { |
| 116 | + "mode": "incremental", |
| 117 | + "template": { |
| 118 | + "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", |
| 119 | + "contentVersion": "1.0.0.0", |
| 120 | + "parameters": { |
| 121 | + "routeTableName": { |
| 122 | + "type": "string" |
| 123 | + }, |
| 124 | + "vnetRegion": { |
| 125 | + "type": "string" |
| 126 | + }, |
| 127 | + "requiredRoutes": { |
| 128 | + "type": "array" |
| 129 | + }, |
| 130 | + "disableBgpPropagation": { |
| 131 | + "type": "bool" |
| 132 | + } |
| 133 | + }, |
| 134 | + "variables": { |
| 135 | + "copyLoop": [ |
| 136 | + { |
| 137 | + "name": "routes", |
| 138 | + "count": "[[[length(parameters('requiredRoutes'))]", |
| 139 | + "input": { |
| 140 | + "name": "[[[concat('route-',copyIndex('routes'))]", |
| 141 | + "properties": { |
| 142 | + "addressPrefix": "[[[split(parameters('requiredRoutes')[copyIndex('routes')], ';')[0]]", |
| 143 | + "nextHopType": "[[[split(parameters('requiredRoutes')[copyIndex('routes')], ';')[1]]", |
| 144 | + "nextHopIpAddress": "[[[if(equals(toLower(split(parameters('requiredRoutes')[copyIndex('routes')], ';')[1]),'virtualappliance'),split(parameters('requiredRoutes')[copyIndex('routes')], ';')[2], null())]" |
| 145 | + } |
| 146 | + } |
| 147 | + } |
| 148 | + ] |
| 149 | + }, |
| 150 | + "resources": [ |
| 151 | + { |
| 152 | + "type": "Microsoft.Resources/deployments", |
| 153 | + "apiVersion": "2021-04-01", |
| 154 | + "name": "routeTableDepl", |
| 155 | + "properties": { |
| 156 | + "mode": "Incremental", |
| 157 | + "template": { |
| 158 | + "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", |
| 159 | + "contentVersion": "1.0.0.0", |
| 160 | + "parameters": { |
| 161 | + "routeTableName": { |
| 162 | + "type": "string" |
| 163 | + }, |
| 164 | + "vnetRegion": { |
| 165 | + "type": "string" |
| 166 | + }, |
| 167 | + "requiredRoutes": { |
| 168 | + "type": "array" |
| 169 | + }, |
| 170 | + "disableBgpPropagation": { |
| 171 | + "type": "bool" |
| 172 | + } |
| 173 | + }, |
| 174 | + "resources": [ |
| 175 | + { |
| 176 | + "type": "Microsoft.Network/routeTables", |
| 177 | + "apiVersion": "2021-02-01", |
| 178 | + "name": "[[[parameters('routeTableName')]", |
| 179 | + "location": "[[[parameters('vnetRegion')]", |
| 180 | + "properties": { |
| 181 | + "disableBgpRoutePropagation": "[[[parameters('disableBgpPropagation')]", |
| 182 | + "copy": "[[variables('copyLoop')]" |
| 183 | + } |
| 184 | + } |
| 185 | + ] |
| 186 | + }, |
| 187 | + "parameters": { |
| 188 | + "routeTableName": { |
| 189 | + "value": "[[parameters('routeTableName')]" |
| 190 | + }, |
| 191 | + "vnetRegion": { |
| 192 | + "value": "[[parameters('vnetRegion')]" |
| 193 | + }, |
| 194 | + "requiredRoutes": { |
| 195 | + "value": "[[parameters('requiredRoutes')]" |
| 196 | + }, |
| 197 | + "disableBgpPropagation": { |
| 198 | + "value": "[[parameters('disableBgpPropagation')]" |
| 199 | + } |
| 200 | + } |
| 201 | + } |
| 202 | + } |
| 203 | + ] |
| 204 | + }, |
| 205 | + "parameters": { |
| 206 | + "routeTableName": { |
| 207 | + "value": "[[parameters('routeTableName')]" |
| 208 | + }, |
| 209 | + "vnetRegion": { |
| 210 | + "value": "[[parameters('vnetRegion')]" |
| 211 | + }, |
| 212 | + "requiredRoutes": { |
| 213 | + "value": "[[parameters('requiredRoutes')]" |
| 214 | + }, |
| 215 | + "disableBgpPropagation": { |
| 216 | + "value": "[[parameters('disableBgpPropagation')]" |
| 217 | + } |
| 218 | + } |
| 219 | + } |
| 220 | + } |
| 221 | + } |
| 222 | + } |
| 223 | + } |
| 224 | + } |
| 225 | + } |
| 226 | + ], |
| 227 | + "outputs": {} |
| 228 | +} |
0 commit comments