Search code examples
azureazure-rm-template

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?


Solution

  • 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.

    enter image description here

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

    enter image description here

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

    enter image description here