1

I have a VNET set up in Azure with a number of subnets each with their own NSG defining inbound and outbound rules.

Into these subnets I would like to deploy VM scale sets with autoscale rules (based on https://raw.githubusercontent.com/gbowerman/azure-myriad/master/vmss-ubuntu-scale/azuredeploy.json for example) with certain extensions (perhaps pulling some repos from github/docker).

In my template how do I define that the scale set / VM should be assigned to an existing subnet/NSG etc?

Stuart Brown
  • 977
  • 2
  • 22
  • 47

1 Answers1

2

Well, that's fairly straight forward, you just need to specify the ID of the resource you are referencing.

Let's say you want to use existing subnet:

"parameters": {
...
    "existingVirtualNetworkName": {
      "type": "string",
      "metadata": {
        "description": "Name of the existing VNET"
      }
    },
    "existingVirtualNetworkResourceGroup": {
      "type": "string",
      "metadata": {
        "description": "Name of the existing VNET resource group"
      }
    },
    "subnetName": {
      "type": "string",
      "metadata": {
        "description": "Name of the subnet in the virtual network you want to use"
      }
    },
...
  },
  "variables": {
...
    "vnetID": "[resourceId(parameters('existingVirtualNetworkResourceGroup'), 'Microsoft.Network/virtualNetworks', parameters('existingVirtualNetworkName'))]",
    "subnetRef": "[concat(variables('vnetID'),'/subnets/', parameters('subnetName'))]",
...
}
  "resources": [
... 
  {
    "apiVersion": "[variables('api-version')]",
    "type": "Microsoft.Network/networkInterfaces",
    "name": "[variables('nicName')]",
    "location": "[resourceGroup().location]",
    "dependsOn": [
      "[concat('Microsoft.Network/publicIPAddresses/', variables('publicIPAddressName'))]"
    ],
    "tags": {
      "displayName": "NetworkInterface"
    },
    "properties": {
      "ipConfigurations": [{
        "name": "ipconfig1",
        "properties": {
          "privateIPAllocationMethod": "Dynamic",
          "publicIPAddress": {
            "id": "[resourceId('Microsoft.Network/publicIPAddresses',variables('publicIPAddressName'))]"
          },
          "subnet": {
            "id": "[variables('subnetRef')]"
          }
        }
      }]
    }
  },

You would use the same approach for the Network Security Group.

Take a look here for more: https://github.com/Azure/azure-quickstart-templates/blob/master/201-vm-specialized-vhd-existing-vnet/azuredeploy.json

4c74356b41
  • 69,186
  • 6
  • 100
  • 141
  • Thanks for the quick answer! In the example: "existingVirtualNetworkName": { "type": "string", "metadata": { "description": "Name of the existing VNET" } if my existing VNET was called stuartVNET would I amend as "stuartVNET": {."type:"string"...} or is 'existing' (existingVirtualNetworkName) some kind of keyword that tells Azure to add to an existing resource and it matches the name from the description value? – Stuart Brown Dec 07 '16 at 21:15
  • Also when I set parameters such as existingVirtualNetworkName, existingVirtualNetworkResourceGroup when I deploy the template using CLI I get prompted to provide values for these i.e. `info: Supply values for the following parameters` `existingVirtualNetworkName:` – Stuart Brown Dec 07 '16 at 21:52
  • 1. no, those are just names, if you don't understand how ARM templates work - read on them. 2. yes, you would need to provide values for all parameters at deployment time. @StuartBrown – 4c74356b41 Dec 08 '16 at 07:17