Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to get Azure storage key from storage resource in ARM template

I'm trying to build a connection string from a storage account used elsewhere in the template and I have

"StorageConnectionString": {
               "value": "[concat('DefaultEndpointsProtocol=https;AccountName=',
 variables('storageName'),';AccountKey=',
 listKeys(resourceId('Microsoft.Storage/storageAccounts',
 variables('storageName')), providers('Microsoft.Storage',
 'storageAccounts').apiVersions[0]).key1)]",
              "type": "Custom"
             },

Which I found from ARM - How can I get the access key from a storage account to use in AppSettings later in the template? however the syntax in that question no longer appears to work. I get an error that key1 is not a property which is known. Apparently there is a property called keys but that is, as one might expect, a structure of some sort. I have been unable to figure out what the property of the primary key is from that structure. I've tried

  • key1 -> Template language expression property 'key1' doesn't exist, available properties are 'keys
  • keys -> The provided parameters for template language function 'concat' are invalid. Either all or none of the parameters must be an array.
  • keys.key1
  • keys.primaryKey
  • keys[0]

All of which have failed. I tried putting an output at the end of the file but outputting keys just seems to output no value.

like image 528
stimms Avatar asked Mar 13 '16 20:03

stimms


People also ask

Where is Azure storage account key?

View account access keysIn the Azure portal, go to your storage account. Under Security + networking, select Access keys. Your account access keys appear, as well as the complete connection string for each key.

How many access keys are provided for accessing your Azure storage account?

According to Azure documentation: “When you create a storage account, Azure generates two 512-bit storage account access keys. These keys can be used to authorize access to data and even the modification (including deletion!) in your storage account via Shared Key authorization.”

Do storage account names need to be unique?

When naming your storage account, keep these rules in mind: Storage account names must be between 3 and 24 characters in length and may contain numbers and lowercase letters only. Your storage account name must be unique within Azure. No two storage accounts can have the same name.

Which two are restrictions for a Storageaccount name in an Azure Resource Manager template?

Storage account name must be between 3 and 24 characters in length and use numbers and lower-case letters only.


2 Answers

As it turns out the structure of the object returned from listKeys is an array of keys which looks like

[
  { "keyName":"key1", "permissions":"Full", "value":"keyvalue1"},
  { "keyName":"key2", "permissions":"Full", "value":"keyvalue2"}
]

So the correct solution to getting the value out was to do keys[0].value.

like image 160
stimms Avatar answered Oct 17 '22 16:10

stimms


You should use the listKeys() function

https://azure.microsoft.com/en-us/documentation/articles/resource-group-template-functions/#listkeys

like image 36
Neil Mackenzie Avatar answered Oct 17 '22 18:10

Neil Mackenzie