1

I am attempting to add availability zone into my VM arm template.

Majority of times I don't want the VM to be in a zone as it is a single VM.

So in my ARM template, I have defined the zone section as:

"zones":[
        "[if(greaterOrEquals(parameters('availabilityZone'), 1),parameters('availabilityZone'),json('null'))]"
      ],

this works fine if I set a value of 1 or higher but fails if I leave as blank.

failed validation with message: 'The zone(s) '' for resource 'Microsoft.Compute/virtualMachines/XXX' is not supported.

if I remove the if condition then hard code in the blank it works:

"zones": "",

I appreciate your help in advance.

Stu

Ashwin Yaprala
  • 2,737
  • 2
  • 24
  • 56

2 Answers2

1

we found the following solution that worked:

"zones": "if(empty(parameters('availabilityZone')),parameters('availabilityZone'),array(parameters('availabilityZone')))]"

0

Please try something like this, if your parameter doesn't contain then it will pass the empty value,

"zones": "[if(empty(parameters('availabilityZone')),'', parameters('availabilityZone'))]",

https://learn.microsoft.com/en-us/azure/azure-resource-manager/templates/template-functions-string?tabs=json#empty