Azure-docs: Reference function not working in true path of if statement

Created on 30 Oct 2018  Â·  7Comments  Â·  Source: MicrosoftDocs/azure-docs

Inside a copy function I have the following statement:
"objectId": "[if(equals(parameters('clusterProvisioningKvAccessPolicies')[copyIndex('accessPolicies')].objectId, 'scalesetIdentity'),reference(resourceId(parameters('clusterProvisioningKvAccessPolicies')[copyIndex('accessPolicies')].resourceGroup, 'Microsoft.ManagedIdentity/userAssignedIdentities','scaleset'), '2015-08-31-PREVIEW', 'Full').properties.principalId,parameters('clusterProvisioningKvAccessPolicies')[copyIndex('accessPolicies')].objectId)]"
which causes the failure "The provided arguments for template language function 'if' is not valid: all arguments should be of type 'boolean'. Please see https://aka.ms/arm-template-expressions#if for usage details."

When I change the reference to a hardcoded the guid it passes.


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

assigned-to-author azure-resource-managesvc product-issue triaged

Most helpful comment

Any update on this? I'm facing a similar issue, except in my case I'm making a reference to one of my VM's MSI principalId.

All 7 comments

@johnthcall Thanks for your comment. The feedback has been shared with the content owner for further review. Thanks for your patience.

@johnthcall - I ran a test with reference as the true path for an if expression within a copy, and it worked as expected. For you scenario, I would suggest looking at the error message stating all arguments should be of type boolean. I am not sure why it would state that. Are you using an if expression to assign a value that expects a Boolean? Or, perhaps the syntax is not resolving correctly.

please-close

@tfitzmac, @johnthcall

I just ran into the same problem, I'm pretty sure the expression is correct and it should be working:

"objectId": "[if(equals(variables('key_vault_members')[copyIndex('accessPolicies')].type, 'ims'), variables('key_vault_members')[copyIndex('accessPolicies')].objectId, reference(concat('Microsoft.Web/sites/', variables('app_name')), '2016-08-01', 'Full').identity.principalId)]"

When I validate the template, the expression gets transformed to this:

"objectId": "[if('False','',reference('Microsoft.Web/sites/deleteme-dev','2016-08-01','Full').identity.principalId)]"

The stringified boolean could explain this error:

Deployment failed. Correlation ID: 5339a446-04ec-4cb1-9faa-09273a4ab699. {
  "error": {
    "code": "InvalidTemplate",
    "message": "Unable to process template language expressions for resource '/subscriptions/fda892b2-7af7-447f-ab15-c06669c056b1/resourceGroups/deleteme/providers/Microsoft.Resources/deployments/nestedTemplate' at line '1' and column '3652'. 'The provided arguments for template language function 'if' is not valid: all arguments should be of type 'boolean'. Please see https://aka.ms/arm-template-expressions#if for usage details.'"
  }
}

But I think its a bug and it should be transformed to if(false, ... insted of if('False', ...

Some more tests:

"dummy": "[if(bool('False'), 'wahr', 'nicht wahr')]",
"objectId": "[reference(concat('Microsoft.Web/sites/', variables('app_name')), '2016-08-01', 'Full').identity.principalId]",
"objectId2": "[if(bool(equals(variables('key_vault_members')[copyIndex('accessPolicies')].type, 'ims')), variables('key_vault_members')[copyIndex('accessPolicies')].objectId, reference(concat('Microsoft.Web/sites/', variables('app_name')), '2016-08-01', 'Full').identity.principalId)]",

Validates to this:

"dummy": "nicht wahr",
"objectId": "[reference(concat('Microsoft.Web/sites/', variables('app_name')), '2016-08-01', 'Full').identity.principalId]",
"objectId2": "[if('False','',reference('Microsoft.Web/sites/deleteme-dev','2016-08-01','Full').identity.principalId)]",

For me, it looks that there are several problems with value resolving. "dummy" resolves completely. "objectId" has an unresolved "app_name". "objectId2" resolves the app-name but leave behind an invalid if construct.

@martinoss - sorry, I should have updated this thread. Yes, the product team is investigating this issue. I have not heard an update about a potential fix.

Any update on this? I'm facing a similar issue, except in my case I'm making a reference to one of my VM's MSI principalId.

I am also facing this issue, can you guys reopen it please?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

spottedmahn picture spottedmahn  Â·  3Comments

behnam89 picture behnam89  Â·  3Comments

ianpowell2017 picture ianpowell2017  Â·  3Comments

JamesDLD picture JamesDLD  Â·  3Comments

jharbieh picture jharbieh  Â·  3Comments