Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.6k views
in Technique[技术] by (71.8m points)

arm template - 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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...