2

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')]"
  ]
}
Antonia
  • 278
  • 3
  • 10
  • where do you get this error? – 4c74356b41 Mar 31 '18 at 11:01
  • Can you post your arm template ? at least the resource you try to inject the access key into it – Thomas Mar 31 '18 at 12:04
  • @4c74356b41 I get this error when deploying template using powershell – Antonia Mar 31 '18 at 21:59
  • @Thomas I've edited the original question, added resource I try to inject this expression in. – Antonia Mar 31 '18 at 22:06
  • In the `"dependsOn"` array, can you try adding this resource `[resourceId('Microsoft.Batch/batchAccounts', parameters('batch_accountName')]` – Thomas Apr 01 '18 at 05:49
  • @Thomas unfortunately that didn't help either. Getting `The resource 'Microsoft.Batch/batchAccounts/my-acc-name' is not defined in the template.` error, as batch account itself is not defined in this template. It is rather an existing resource, and I only need its access key to create Data Factory Linked Service for that batch account. Of course, I could just create parameter 'batch_accessKey' in ARM template, but I would rather avoid having to put key in there if I could fetch it by listKey expression somehow. – Antonia Apr 01 '18 at 10:40
  • @Thomas I added batch account as resource to the template and now it works, so thank you very much for the tip. If you will post your comment as an answer, I will accept it. Cheers! – Antonia Apr 01 '18 at 11:02
  • Good to here. I will wirte an answer a little bit later, trying to explain why you have this behavior in the ARM template – Thomas Apr 01 '18 at 11:54

1 Answers1

0

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.

Thomas
  • 24,234
  • 6
  • 81
  • 125