简体   繁体   中英

Azure availability zone ARM A parameter syntax

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

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://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/template-functions-string?tabs=json#empty

we found the following solution that worked:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM