How can we improve the Azure Resource Manager?

Support zero as a valid count in a resource loop

We are developing an Azure Marketplace solution using ARM templates. The software we are exposing in this solution has the concept of worker machines, and a user may desire N of them, where N can be arbitrarily large or small. Indeed, the user may wish to have 0 workers and this makes total sense within the software.

The most straightforward way to provide this features is through the use of ARM resource loops. The user provides their desired number of workers as a parameter, and a resource loop stamps out that number of machines from a template with a unique identity constructed from the copy mechanism.

Unfortunately, a resource loop must always contain at least one of the declared resource. This seems unnecessarily restrictive. If you think of a resource loop as a collection of resources, zero makes total sense.

160 votes
Sign in
Sign in with: Microsoft
Signed in as (Sign out)

We’ll send you updates on this idea

Alex Stoddard shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →


Sign in
Sign in with: Microsoft
Signed in as (Sign out)
  • Richard Cheney commented  ·   ·  Flag as inappropriate

    Very disappointing.

    It is interesting the Hashicorp took the decision to significantly rework Terraform for v0.12 to clean it up and remove the need for ugly and non-intuitive workarounds.

  • RichCheneyAzure commented  ·   ·  Flag as inappropriate

    @Klaas, was the before or after the Jan 11th date when the governance team posted above? It would be incredibly disappointing if this elegant solution wasn't implemented.

    I wrote a workaround for something more complicated than the dataDisks examples (a nested subnets array in , that uses variables('dummyArray') if there are no subnets to create), and a few months later I struggle to understand the syntax. These ugly workarounds need to go!

  • Todd Cotten commented  ·   ·  Flag as inappropriate

    This is definitely an important feature for anyone doing reusable arm templates. Take data disks in an IAAS VM as an example. If you are using a VM copy loop to say create some web servers that may or may not need data disks there really isn't a way to accomplish this cleanly without getting into non-resource creating linked templates with references to outputs or managing two VM resources that are almost exactly the same. You can't use conditions on property copy loops which frankly is just a Band-Aid for this feature anyway. Variable copy loops don't have access to the VM copy loops index and functions can't implement loops at this time.

  • john commented  ·   ·  Flag as inappropriate

    I would love to know logically why MS decided to implement the copy function like this - it's one of those ARM gems that makes life as an ARM developer incredibly frustrating

  • Owain Winterbone commented  ·   ·  Flag as inappropriate

    Yes I've just encounted this as well when trying to use it to replace the array currently used to dynamically provision data disks to a VM - really, really annoying. Will have to go back to the rather ungainly array or see if I can use conditions to get round the problem - highly unlikely to work I imagine.

  • Stanley Merkx commented  ·   ·  Flag as inappropriate

    Yes, we really need this! Why can't I give more than 3 votes??!?!?

    Would be a very elegant way conditionally setting properties within a resource. For example: I have implemented a copy loop to add data datadisks when deploying a VM and passing all parameters (name, size, type, lun) via een array of objects.

    But: if I don't want any datadisks and set count = 0, the copy barfs where it should simply do nothing.

  • Michael commented  ·   ·  Flag as inappropriate

    Agreeing with this as well. I can take my deployment model from 9 nested templates to 3 if this were implemented.

  • Phil commented  ·   ·  Flag as inappropriate

    Seconded, I am in a similar situation where our own deployments of infrastructure may not require all the components in a template. Presently I have to use scripted uploads + conditional inclusion of nested templates whereas supporting a count of zero would be considerably cleaner and more maintainable.

Feedback and Knowledge Base