Search code examples
azureazure-resource-managerazure-rm-template

Trying to use Azure ARM template with object parameter but stuck with an invalid index error


I am currently trying to get an Azure storage key using the following:

"accessKey": "[listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('myParameter').azureblob.storageAccountName), '2019-04-01').keys[0].value]"

My parameter is defined as:

"LogicAppConnections": {
        "value": {
            "azureblob": [
                {
                    "storageAccountName": "myAccountName"
                }
            ]
        }
 }

This is the exception I am getting from the validator:

Template validation failed: The template resource 'XYZ' at line '84' and column '9' is not valid: The language expression property 'storageAccountName' has an invalid array index.. Please see https://aka.ms/arm-template-expressions for usage details.

Anyone knows what can be the issue?

Thank you


Solution

  • because its an array you have to index into it:

    parameters('myParameter').azureblob[0].storageAccountName
    

    or do this:

    first(parameters('myParameter').azureblob)).storageAccountName