question

RameshR-9941 avatar image
0 Votes"
RameshR-9941 asked ·

ARM template to create multiple VMs having different VM Sizes and OS.

I am looking for a generic ARM template that can create multiple VMs each having different VM Size and OS image. Plan is to pass VM names, VM Sizes and OS configurations as parameter arrays to the ARM template during deployment. Template linking is a solution but I am more interested in implementing a template that can loop itself to create multiple resources.

azure-dtl-arm-enviormentsazure-lab-services-templates-virtual-machinesazure-dtl-automation
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

SamaraSoucyMSFT avatar image
0 Votes"
SamaraSoucyMSFT answered ·

This is possible using the copy property in the template where you want to make use of your parameter array.

A simple example is something like this:

 "parameters": {
   "org": {
     "type": "array",
     "defaultValue": [
       "contoso",
       "fabrikam",
       "coho"
     ]
   }
 },
 "resources": [
   {
     "name": "[concat('storage', parameters('org')[copyIndex()])]",
     "copy": {
       "name": "storagecopy",
       "count": "[length(parameters('org'))]"
     },
     ...
   }
 ]

The copyIndex function allows the template to grab the correct value from the parameter array and the count is set by the length() function so that you don't have to set that manually.

You can read up on how to make use of the property in different scenarios in the docs: https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-create-multiple#resource-iteration

The linked template docs also discuss the copy property when it comes to working with nested templates: https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-linked-templates#using-copy


· Share
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.