0

I created a linux image and my intention is to create other VMs from the same VHD. These VMs would need to be in an availability set - so is there a param to specify the availability set name using this command?

azure group deployment create --resource-group myRG --template-file temp.json

Ref: https://azure.microsoft.com/en-gb/documentation/articles/virtual-machines-linux-capture-image/

sendmarsh
  • 1,046
  • 7
  • 11
mr i.o
  • 952
  • 2
  • 10
  • 20

1 Answers1

1

In your temp.json file add the availabilitySetName as a variable (change accordingly):

"variables": {
 ...
  "availabilitySetName": "myAvSet",
 ...
 }

Then add it as a resource:

"resources": [
 ...
 {
  "type": "Microsoft.Compute/availabilitySets",
  "name": "[variables('availabilitySetName')]",
  "apiVersion": "2015-06-15",
  "location": "[resourceGroup().location]",
  "properties": {}
 }
 ...

Down further still inside "resources", find the virtual machine that you want to add to an availabilitySet and make it dependable on your availabilitySet resource. Just after modifying dependsOn, add it to the properties object.

 {
  "apiVersion": "2015-06-15",
  "type": "Microsoft.Compute/virtualMachines",
  ...
  "dependsOn": [
    ...
    "[concat('Microsoft.Compute/availabilitySets/', variables('availabilitySetName'))]"
    ...
  ],
  "properties": {
    ...
    "availabilitySet": {
      "id": "[resourceId('Microsoft.Compute/availabilitySets',variables('availabilitySetName')) ]"
    }
  ...
  }

Update:

When creating a VM from an image, the easiest way is to just create the availability set before deploying the template just like we already do with the network interface. In this case, you only have to reference the resource in "properties" object.

"properties": {
    ...
    "availabilitySet": {
      "id": "[resourceId('Microsoft.Compute/availabilitySets', 'myAsName') ]"
    }
  ...
Bruno Faria
  • 5,219
  • 3
  • 24
  • 27
  • Thanks for the response, but I can't find the Depend's on bit in the JSON that was auto-generated when I created the image. – mr i.o Oct 22 '16 at 16:13
  • maybe this sample can help you https://github.com/Azure/azure-quickstart-templates/blob/master/201-2-vms-internal-load-balancer/azuredeploy.json. If you don't have it, add it :) – Bruno Faria Oct 22 '16 at 16:14
  • This is what was auto-generated - https://gist.github.com/iogbole/df04a510ce5671e69497073735e74ff9. Would it be better to replace the VHD url in the template you linked with mine? Thanks again – mr i.o Oct 22 '16 at 16:20
  • well, in this case, it's easier to just create the Availability Set resource beforehand and add it as a property. See line 29. https://gist.github.com/anonymous/6721e19bfee773eafe41782da270a41e – Bruno Faria Oct 22 '16 at 17:18
  • That worked, thank you so much. Can't wait for when MS makes it easy to add/remove VMs to/from availability sets via the portal. – mr i.o Oct 22 '16 at 17:41
  • yea! Oddly, they have this feature in classic mode (ASM), but not in ARM yet. I'll update the answer. Please, if it worked for you, don't forget to mark it as an answer :) – Bruno Faria Oct 22 '16 at 17:42