简体   繁体   中英

if condition in ARM Template resource

I have a resource in my Arm Template as follows:

parameters:

env
prodparam
nonprodparam

resources:

{
  "type": "Microsoft.Resources/deployments",
  "apiVersion": "2018-05-01",
  "url": "[if(equals(parameters('env'),'prod'), parameters('prodparam'), parameters('nonprodparam'))]"
}

I see the url is always set to parameters('nonprodparam') even if parameters('env') = 'prod'. Is this if condition correct? Am I missing something?

Your if condition statement is correct, I tested it and got the correct result successfully.

You need to do the following steps to check where your problem is:

1. Check if your parameter definition is correct, especially as Stringfellow mentioned in the comment, to be case sensitive. It should be defined as follows.

在此处输入图片说明

2. Pay attention to whether to save after editing arm templates in the azure portal.

在此处输入图片说明

You can check the value of the parameter during the deployment process:

在此处输入图片说明

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