0

unable to fetch single access key value from array, i followed this reference https://stackoverflow.com/a/50407157/11191182

"storageAccountAccessKey": "[listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('StorageAccountName')), '2017-10-01').key]",

Error

The language expression property 'key1' doesn't exist, available properties are 'keys'.'",

  • try `.keys[0]`, it depends on which API version you use. – Daniel Morritt Feb 04 '20 at 16:29
  • I added this "storageAccountAccessKey": "[listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('StorageAccountName')), '2017-10-01').keys[0]]", but it throws error like { The 'parameters.properties.storageAccountAccessKey' segment in the url is invalid } I use apiVersion - 2017-10-01 – prachi sawant Feb 05 '20 at 05:14
  • Hi @prachi sawant Did you tried `.keys[0].value`, how did it go? – Levi Lu-MSFT Feb 06 '20 at 12:51

1 Answers1

0

.key1 is an old version of the function listKeys. The syntax now is .keys[0].value.

 "StorageAccount": "[Concat('DefaultEndpointsProtocol=https;AccountName=',variables('StorageAccountName'),';AccountKey=',listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('StorageAccountName')), providers('Microsoft.Storage', 'storageAccounts').apiVersions[0]).keys[0].value)]"  

Update: For .key1 syntax you can try using the older version api (2015-05-01-preview). Please refer to below example:

"accessKey": "[listKeys(variables('storageAccountid'),'2015-05-01-preview').key1]"

For more information please refer to blog Retrieve Azure Storage Key in ARM Script

Levi Lu-MSFT
  • 27,483
  • 2
  • 31
  • 43
  • Ahh, I forgot about the `.value` bit, yes that should do it. I'm also against using floating versions for these calls, since you could get future versions of the API which are incompatible (so `.keys[0].value` becomes `.primaryKey` or something), the last thing I want to do is have a template stop working without any changes. – Daniel Morritt Feb 05 '20 at 17:00
  • yes I tried that one it's perfectly working but if want to pass key1 or primarykey instead of keys[0].value then its fails – prachi sawant Feb 07 '20 at 06:14
  • Hi @prachisawant if you want to use key1, you need to use the older version of api `2015-05-01-preview` – Levi Lu-MSFT Feb 11 '20 at 01:58
  • Hi @prachisawant Did you specify an older version of api according above update. Please [accept above answer](https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work) if it answers your question. – Levi Lu-MSFT Feb 16 '20 at 13:33