Skip to content

Instantly share code, notes, and snippets.

@StefanIvemo
Created November 19, 2020 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save StefanIvemo/1862a1401fa982cc8f124a6148eda5f5 to your computer and use it in GitHub Desktop.
Save StefanIvemo/1862a1401fa982cc8f124a6148eda5f5 to your computer and use it in GitHub Desktop.
UpdateSubnetTemplate.json
{
"$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"
}
},
"resources": [
{
"type": "Microsoft.Network/networkSecurityGroups",
"apiVersion": "2020-05-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",
"apiVersion": "2020-05-01",
"name": "[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-05-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": {
"id": "[resourceId('Microsoft.Network/routeTables', parameters('SubnetInfo')[copyIndex()].properties.RouteName)]"
}
}
}
]
}
}
}
]
}
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"value": "westeurope"
},
"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": "subnet2-routes",
"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": [
{
"name": "default-outbound-to-firewall",
"properties": {
"addressPrefix": "0.0.0.0/0",
"nextHopType": "VirtualAppliance",
"nextHopIpAddress": "10.0.0.4"
}
}
]
}
},
{
"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": "subnet4-routes",
"SecurityRules": [],
"disableBgpRoutePropagation": false,
"routes": []
}
}
]
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment