ARM - How can I get the access key from a storage account to use in AppSettings later in the template?

Scott picture Scott · Oct 20, 2015 · Viewed 20.8k times · Source

I'm creating an Azure Resource Manager template that instantiates multiple resources, including an Azure storage account and an Azure App Service with a Web App.

I'd like to be able to capture the primary access key (or the full connection string, either way is fine) from the newly-created storage account, and use that as a value for one of the AppSettings for the Web App.

Is that possible?

Answer

BenV picture BenV · Oct 20, 2015

Use the listkeys helper function.

"appSettings": [
    {
      "name": "STORAGE_KEY",
      "value": "[listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName')), providers('Microsoft.Storage', 'storageAccounts').apiVersions[0]).keys[0].value]"
    }
]

This quickstart does something similar:

https://azure.microsoft.com/en-us/documentation/articles/cache-web-app-arm-with-redis-cache-provision/