Created
January 11, 2021 07:56
-
-
Save StefanIvemo/d9fecb77d9089bd282638aa52a2fffb2 to your computer and use it in GitHub Desktop.
UpdateSubnetTemplate_v2.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#", | |
"contentVersion": "1.0.0.0", | |
"parameters": { | |
"location": { | |
"value": "eastus" | |
}, | |
"VNetName": { | |
"value": "super-vnet" | |
}, | |
"SubnetInfo": { | |
"value": [ | |
{ | |
"properties": { | |
"NSGName": "subnet1-nsg", | |
"SubnetName": "subnet1", | |
"RouteName": "subnet1-routes", | |
"securityRules": [ | |
{ | |
"name": "Inbound_Deny_All", | |
"properties": { | |
"description": "Deny all inbound traffic", | |
"protocol": "*", | |
"sourcePortRange": "*", | |
"sourceAddressPrefix": "*", | |
"destinationPortRange": "*", | |
"destinationAddressPrefix": "*", | |
"access": "Deny", | |
"priority": 4096, | |
"direction": "Inbound" | |
} | |
} | |
], | |
"disableBgpRoutePropagation": true, | |
"routes": [ | |
{ | |
"name": "default-outbound-to-firewall", | |
"properties": { | |
"addressPrefix": "0.0.0.0/0", | |
"nextHopType": "VirtualAppliance", | |
"nextHopIpAddress": "10.0.0.4" | |
} | |
} | |
] | |
} | |
}, | |
{ | |
"properties": { | |
"NSGName": "subnet2-nsg", | |
"SubnetName": "subnet2", | |
"RouteName": "", | |
"securityRules": [ | |
{ | |
"name": "Outbound_Deny_All", | |
"properties": { | |
"description": "Deny all inbound traffic", | |
"protocol": "*", | |
"sourcePortRange": "*", | |
"sourceAddressPrefix": "*", | |
"destinationPortRange": "*", | |
"destinationAddressPrefix": "*", | |
"access": "Deny", | |
"priority": 4096, | |
"direction": "Outbound" | |
} | |
} | |
], | |
"disableBgpRoutePropagation": true, | |
"routes": [] | |
} | |
}, | |
{ | |
"properties": { | |
"NSGName": "subnet3-nsg", | |
"SubnetName": "subnet3", | |
"RouteName": "subnet3-routes", | |
"securityRules": [ | |
{ | |
"name": "Inbound_Allow_Http", | |
"properties": { | |
"description": "Allow inbound http traffic", | |
"protocol": "TCP", | |
"sourcePortRange": "*", | |
"sourceAddressPrefix": "*", | |
"destinationPortRange": "80", | |
"destinationAddressPrefix": "*", | |
"access": "Allow", | |
"priority": 4096, | |
"direction": "Inbound" | |
} | |
} | |
], | |
"disableBgpRoutePropagation": false, | |
"routes": [ | |
{ | |
"name": "default-outbound-to-firewall", | |
"properties": { | |
"addressPrefix": "0.0.0.0/0", | |
"nextHopType": "VirtualAppliance", | |
"nextHopIpAddress": "10.0.0.4" | |
} | |
} | |
] | |
} | |
}, | |
{ | |
"properties": { | |
"NSGName": "subnet4-nsg", | |
"SubnetName": "subnet4", | |
"RouteName": "", | |
"SecurityRules": [], | |
"disableBgpRoutePropagation": false, | |
"routes": [] | |
} | |
} | |
] | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", | |
"contentVersion": "1.0.0.0", | |
"parameters": { | |
"location": { | |
"type": "string" | |
}, | |
"VNetName": { | |
"type": "string", | |
"metadata": { | |
"description": "description" | |
} | |
}, | |
"SubnetInfo": { | |
"type": "array" | |
} | |
}, | |
"variables": { | |
"copy": [ | |
{ | |
"name": "routetableid", | |
"count": "[length(parameters('SubnetInfo'))]", | |
"input": { | |
"id": "[if(empty(parameters('SubnetInfo')[copyIndex('routetableid')].properties.RouteName),'fakeid',resourceId('Microsoft.Network/routeTables', parameters('SubnetInfo')[copyIndex('routetableid')].properties.RouteName))]" | |
} | |
} | |
] | |
}, | |
"resources": [ | |
{ | |
"type": "Microsoft.Network/networkSecurityGroups", | |
"apiVersion": "2020-07-01", | |
"name": "[concat(parameters('SubnetInfo')[copyIndex()].properties.NSGName)]", | |
"location": "[parameters('Location')]", | |
"copy": { | |
"name": "NSGs", | |
"count": "[length(parameters('SubnetInfo'))]" | |
}, | |
"properties": { | |
"securityRules": "[parameters('SubnetInfo')[copyIndex()].properties.SecurityRules]" | |
} | |
}, | |
{ | |
"type": "Microsoft.Network/routeTables", | |
"condition": "[not(empty(parameters('SubnetInfo')[copyIndex()].properties.RouteName))]", | |
"apiVersion": "2020-07-01", | |
"name": "[if(empty(concat(parameters('SubnetInfo')[copyIndex()].properties.RouteName)), concat('mock', copyIndex()), concat(parameters('SubnetInfo')[copyIndex()].properties.RouteName))]", | |
"location": "[parameters('Location')]", | |
"copy": { | |
"name": "Routes", | |
"count": "[length(parameters('SubnetInfo'))]" | |
}, | |
"properties": { | |
"routes": "[parameters('SubnetInfo')[copyIndex()].properties.Routes]", | |
"disableBgpRoutePropagation": "[parameters('SubnetInfo')[copyIndex()].properties.disableBgpRoutePropagation]" | |
} | |
}, | |
{ | |
"type": "Microsoft.Resources/deployments", | |
"apiVersion": "2020-06-01", | |
"name": "[concat('update-',parameters('SubnetInfo')[copyIndex()].properties.SubnetName)]", | |
"dependsOn": [ | |
"NSGs", | |
"Routes" | |
], | |
"copy": { | |
"name": "association", | |
"count": "[length(parameters('SubnetInfo'))]", | |
"mode": "Serial" | |
}, | |
"properties": { | |
"mode": "Incremental", | |
"template": { | |
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", | |
"contentVersion": "1.0.0.0", | |
"resources": [ | |
{ | |
"apiVersion": "2020-07-01", | |
"type": "Microsoft.Network/virtualNetworks/subnets", | |
"name": "[concat(parameters('VNetName'), '/', parameters('SubnetInfo')[copyIndex()].properties.SubnetName)]", | |
"location": "[resourceGroup().location]", | |
"properties": { | |
"addressPrefix": "[reference(resourceId(resourceGroup().name, 'Microsoft.Network/virtualNetworks/subnets', parameters('VNetName'), parameters('SubnetInfo')[copyIndex()].properties.SubnetName), '2018-03-01').addressPrefix]", | |
"networkSecurityGroup": { | |
"id": "[resourceId('Microsoft.Network/networkSecurityGroups', parameters('SubnetInfo')[copyIndex()].properties.NSGName)]" | |
}, | |
"routeTable": "[if(empty(parameters('SubnetInfo')[copyIndex()].properties.RouteName), json('null') ,variables('routetableid')[copyIndex()])]" | |
} | |
} | |
] | |
} | |
} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment