I am using if()
functions in my ARM template to conditionally set some connection string values in my Web App resource. The current condition looks like this.
"[if(equals(parameters('isProduction'), 'Yes'), concat(variables('redisCacheName'),'.redis.cache.windows.net:6380|', listKeys(resourceId('Microsoft.Cache/Redis', variables('redisCacheName')), '2015-08-01').primaryKey, '|', variables('resourcePrefix')), parameters('redisSessionStateConnection'))]"
To simplify it, the condition looks like this;
[if(equals(arg1, arg2), true_expression, false_expression)]
When I deploy the ARM template with isProduction
parameter set to No
the execution throws an exception. When isProduction
parameter is set to Yes
then the template works fine. The exceptions is related to ARM trying to find the redis cache resource which will not be deployed in non production environment.
My guess is even if the isProduction
parameter value is No
, the true_expression in the above condition which is referencing the Redis Cache resource is getting executed and since the Redis Cache resource is not created in a non production state, it throws the exception.
So my question is, when we have a condition like above, will the true_expression and the false_expression in the if()
function is evaluated before the actual condition of the if()
function is executed?
If so what would be possible workarounds to get around this problem?
My guess would be:
no, only theyes, both expressionsneeded based on the outcome of the if statement isare evaluated.To solve your issue: you can use environment specific parameter files. This enables you to only include parameters for the environment you're deploying to.
See the documentation on parameters in the 'Understand the structure and syntax of Azure Resource Manager templates' article.
Both sides of
if()
are evaluated regardless (in ARM templates). so you have to work around that using "clever" ways.you could use nested deployments\variables to try and work around that.
update: this has been fixed some time ago, only the relevant part of
if()
function is evaluated.