Forum Discussion

LilyC3031's avatar
LilyC3031
Copper Contributor
May 18, 2021

Associate NSG to second subnet in ARM template

Just starting my ARM template experience and have gotten to the point of creating a virtual network, 2 subnets, and an NSG. The NSG associates to one subnet, but I am stuck on how to associate the NSG to the second subnet. I thought about using "copy" but that didn't seem quite right in this config. 

 

Any help would be REALLY appreciated! 

 

Config is below and also attached.

 

{
  "$schema""https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion""1.0.0.0",
  "parameters": {
    "vnetName": {
        "type""string",
        "defaultValue""vnet-name",
        "metadata": {
          "description""VNet name"
      }
    },
    "addressSpaceVnet": {
      "type""string",
      "defaultValue""10.0.0.0/16",
      "metadata": {
          "description""vNet Address prefix"
      }
    },
    "subnet1Name": {
        "type""string",
        "defaultValue""subnet1-name",
        "metadata": {
          "description""Subnet 1 Name"
      }
    },
    "addressSpaceSubnet1": {
      "type""string",
      "defaultValue""10.0.0.0/24",
      "metadata": {
          "description""Subnet 1 Prefix"
      }
    },
    "subnet2Name": {
        "type""string",
        "defaultValue""subnet2-name",
        "metadata": {
          "description""Subnet 2 Name"
      }
     },
    "addressSpaceSubnet2": {
      "type""string",
      "defaultValue""10.0.1.0/24",
      "metadata": {
          "description""Subnet 2 Prefix"
        }
      }
   },
  "resources": [
    {
      "apiVersion""2015-06-15",
      "type""Microsoft.Network/virtualNetworks",
      "name""[parameters('vnetName')]",
      "location""[resourceGroup().location]",
      "properties": {
        "addressSpace": {
          "addressPrefixes": [
            "[parameters('addressSpaceVnet')]"
          ]
        },
        "subnets": [
          {
            "name""[parameters('subnet1Name')]",
            "properties": {
              "addressPrefix""[parameters('addressSpaceSubnet1')]"
            }
          },
          {
            "name""[parameters('subnet2Name')]",
            "properties": {
              "addressPrefix""[parameters('addressSpaceSubnet2')]"
            }
          }
        ]
      }
    }
  ]
}

Resources