2
votes

In my ARM template, I want to fetch primary key for batch account specified by batch_accountName parameter. Expression that should fetch keys for batch account is:

"[listKeys(resourceId('Microsoft.Batch/batchAccounts', parameters('batch_accountName')), '2017-09-01')]"

And it returns object like below:

{
  "accountName": "my-acc-name",
  "primary": "***",
  "secondary": "***"
}

Now, I've been trying unsuccessfully to fetch azure batch account primary key using the following expression (only difference to above expression is that I've added .primary in order to fetch that property of object):

"[listKeys(resourceId('Microsoft.Batch/batchAccounts', parameters('batch_accountName')), '2017-09-01').primary]"

The error I get is: Index (zero based) must be greater than or equal to zero and less than the size of the argument list.., which implies, if I understand correctly, that listKeys should return an array. But really, it returns an object like shown above.

I've only learned about ARM templates yesterday so I may be doing something wrong, which is not obvious to me at the moment, and I haven't stumbled across such error in the wastelands of the internet, people usually ask about fetching storage keys, which works fine for me, it's batch account keys I'm unable to fetch.

EDIT:

Here's the resource where I try to inject this expression. The resource is a batch linked service in Data Factory.

{
  "name": "[concat(parameters('factoryName'), '/AzureBatchLinkedService')]",
  "type": "Microsoft.DataFactory/factories/linkedServices",
  "apiVersion": "2017-09-01-preview",
  "properties": {
    "type": "AzureBatch",
    "typeProperties": {
      "accountName": "[parameters('batch_accountName')]",
      "accessKey": {
        "type": "SecureString",
        "value": "[listKeys(resourceId('Microsoft.Batch/batchAccounts', parameters('batch_accountName')), '2017-09-01').primary]"
      },
      "batchUri": "[concat('https://', parameters('batch_accountName'), '.' , parameters('batch_region'), '.batch.azure.com')]",
      "poolName": "[parameters('batch_poolName')]",
      "linkedServiceName": {
        "referenceName": "AzureStorageLinkedService",
        "type": "LinkedServiceReference"
      }
    }
  },
  "dependsOn": [
    "[concat(variables('factoryId'), '/linkedServices/AzureStorageLinkedService')]"
  ]
}
1
where do you get this error?4c74356b41
Can you post your arm template ? at least the resource you try to inject the access key into itThomas
@4c74356b41 I get this error when deploying template using powershellAntonia
@Thomas I've edited the original question, added resource I try to inject this expression in.Antonia
In the "dependsOn" array, can you try adding this resource [resourceId('Microsoft.Batch/batchAccounts', parameters('batch_accountName')]Thomas

1 Answers

0
votes

To be sure that the referenced resource has been provisioned successfully, you should declare it a a dependency, Add this line in the "dependsOn" array:

[resourceId('Microsoft.Batch/batchAccounts', parameters('batch_accountName')]

Also to use a resource as a dependency, it has to be declared in the template.