Allow count = 0 for copy in ARM template
Copy command for ARM templates has a paramter called count which determines the number of times it iterates to create the resource. This paramter must take a positive number (not 0). This causes a problem when a template could be reused but the resource that copy applies to is not needed, so the count could be set to 0.
Thanks for the valid suggestion. Your feedback is now open for the user community to upvote which allows us to effectively prioritize your request against our existing feature backlog and also gives us insight into the potential impact of implementing the suggested feature.
Alex Frankel commented
I don't have permissions to close this, but for those who come later, this has been fixed and we now allow a count of zero. Note of caution, we still evaluate the "copied" resource/var/ etc even if the count is 0. We expect this secondary issue to be resolved in the next 2 months.
Harvey, Mark L. commented
There's a workaround described here:
Combining a condition (to check is length of array is 0) and replacing the length with 1 if it is zero, so the resulting ARM is valid, but the resource won't get created because of the condition.
Here's a more complex example - every property that references the zero length array needs to be wrapped in an 'if' condition:
"name": "[concat(parameters('sqlServerName'), '/', if(equals(length(parameters('virtualNetworks').virtualNetworks), 0), 'dummy', parameters('virtualNetworks').virtualNetworks[copyIndex()].subnetName))]",
"count": "[if(equals(length(parameters('virtualNetworks').virtualNetworks), 0), 1, length(parameters('virtualNetworks').virtualNetworks))]"
"virtualNetworkSubnetId": "[if(equals(length(parameters('virtualNetworks').virtualNetworks), 0), 'dummy', parameters('virtualNetworks').virtualNetworks[copyIndex()].subnetId)]",
Would be nicer if this was allowed in the ARM template, so this workaround is not required.
Rick Shahid commented
I have run into this restriction as well. It would be a great enhancement to allow copy count to be 0, which would enable reuse of conditional resource deployment in an ARM template