Reputation: 987
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?
Upvotes: 1
Views: 919
Reputation: 72201
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
Upvotes: 2