Azure ARM Templates Tips and Tricks 4: Oh no, I cannot create dynamic arrays in the templates and pass them on the actual parameter list of templates

This is an interesting problem that comes with the territory (of JSON spec that is). We are hoping Microsoft will come with a solution for this in the future, but for the time being, the solution is a bit ghastly.

This problem manifests itself in places like, adding data disks based on VM size (in Azure, different VM sizes allow different maximum number of data disks that can be attached to them. Please see this article for details) or number of nics for clusters of different sizes. Unfortunately the solution here is to create clones of VM deployment templates for different VM sizes, each with hardcoded JSON arrays for disks, and reference them with the techniques described above.

Let’s go through the solution here. You will notice a set of variables that are complex objects, with the naming convention “tshirtSize*” which can be “tshirtSizeSmall” etc.

  1. You need to provide a tshirt size to the template when deploying, that can be “Small”, “Medium” and “Large”.
  2. This will set the value of the variable “clusterSpec” with clusterSpec: [variables(concat(‘tshirtSize’, parameters(‘tshirtSize’)))]
  3. The clusterSpec will contain the name of one of the “tshirtSize*” variables.
  4. In that variable, you will notice the vmTemplate property will be pointing to one of the templates clones

Next tip