Forum Discussion
ARM Template To create Multiple NSG's associate with existing Subnet
- Nov 17, 2020
Hi!
I've put together a template for you that solves your problem using copy loops for both the NSGs and the subnet association. You can find it here: https://gist.github.com/StefanIvemo/31cda6faa214824b2049a1e98f0e279b
I've created a parameter called NSGs of the type array in the template. Take a look at the example parameter file and adjust it to your needs. All you have to do is add/remove objects to the array and fill in NSGName, SubnetName and your SecurityRules.
The template will first deploy all the NSGs and then do a nested deployment to do the subnet association.
Good luck with your deployment!
You can continue with the template I provided. Just add a property for routes to the parameter file for each of the objects in the array, the same way as for securityRules. E.g. "routes": [], and add your custom routes to it.
Then create a copy loop to create Microsoft.Network/routeTables just like the one for NSGs but modify the properties to work with the Route Table resource.
In the nested deploy where the NSG is associated with the subnet you add the routeTable property.
Good luck!
Hi,
Thanks for the quick update.....
I have modified as per your request but deployment is failing. Below is the Modified Template and Para files.
- StefanIvemoNov 19, 2020Brass Contributor
I've updated the NSG template provided earlier with route tables as well. You can find it here:
https://gist.github.com/StefanIvemo/1862a1401fa982cc8f124a6148eda5f5
You can now deploy NSGs and Route Tables at the same time and update the subnets.
Hope it works for you!
- vigneshkrcegmailcomDec 01, 2020Brass Contributor
Hi Stefan,
This is working as expected, Is it possible to create Multiple Routes inside One Route Table using this Same template and para files.
Can you please help me to create Multiple Routes inside route Table.
https://gist.github.com/StefanIvemo/1862a1401fa982cc8f124a6148eda5f5
I am trying to add two Routes inside one route table as below but i am not able to get it, Can you please help on this.
"disableBgpRoutePropagation": true,"routes": [{"name": "Route1","properties": {"addressPrefix": "0.0.0.0/0","nextHopType": "VirtualAppliance","nextHopIpAddress": "10.0.0.4"}},[{"name": "Route2","properties": {"addressPrefix": "0.0.0.0/0","nextHopType": "VirtualAppliance","nextHopIpAddress": "10.0.0.5"}}]]Regards,
Vignesh
- StefanIvemoDec 01, 2020Brass Contributor
You can add additional routes by adding another route object in the routes array in the parameter file:
"routes": [{"name": "route1","properties": {"addressPrefix": "10.0.0.0/24","nextHopType": "VirtualAppliance","nextHopIpAddress": "10.0.0.4"}},{"name": "route2","properties": {"addressPrefix": "10.10.0.0/24","nextHopType": "VirtualAppliance","nextHopIpAddress": "10.10.0.68"}}]Your example is almost correct, you have some square brackets [] in the wrong place.