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!
In my opinion a subnet should always be created with a route table and NSG. If you don't need any custom routes just edit the parameter file and set the following properties for the subnets where you don't need any custom routing. With no routes and disableBgpRoutePropagation set to false the subnet will use the default routing in Azure even with a route table associated to the subnet.
"disableBgpRoutePropagation": false,
"routes": []
If/when the time comes to add a custom route to the subnet, the route table is there and you can just inject the routes to it.
Hi Stefan,
Any update on this please, The point is we don't need to create Route tables while running the script. If we need Route table we will add Route Property in parameter files. But while doing with this script it is throwing error. I am not sure how to modify Template file accordingly !!!
Vignesh