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
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.
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.
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.”
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.
Storage account name must be between 3 and 24 characters in length and use numbers and lower-case letters only.
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
.
You should use the listKeys() function
https://azure.microsoft.com/en-us/documentation/articles/resource-group-template-functions/#listkeys
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With