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

Ramesh R 1 Reputation point
2019-12-11T06:44:49.73+00:00

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 DevTest Labs
Azure DevTest Labs
An Azure service that is used for provisioning development and test environments.
279 questions
Azure Lab Services
Azure Lab Services
An Azure service that is used to set up labs for classrooms, trials, development and testing, and other scenarios.
298 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Samara Soucy - MSFT 21 Reputation points
    2019-12-11T20:41:45.033+00:00

    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://zcusa.951200.xyz/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://zcusa.951200.xyz/en-us/azure/azure-resource-manager/resource-group-linked-templates#using-copy

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.