azure-quickstart-templates
azure-quickstart-templates copied to clipboard
listKeys not supported in variable
If I use listKeys()
in a variable, I get the error:
The template function 'listKeys' is not expected at this location
for example:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"variables": {
"storageAccountKey": "[listKeys(resourceId('Microsoft.Storage/storageAccounts/mystorageaccount)),'2015-06-15').key1]"
}
}
Can support for listKeys inside a variable be added?
Adding @ravbhatnagar @rjmax from the ARM team for this request
Ran into the same thing. Not a huge drama of course but it would be nice.
FYI my scenario was I was looking to grab the connection string to my storage that I just created and give it to both my webjob as a connection string in the app service and as output for other parts of my deployment (occurring in octopus deploy).
Do we know if this is available now?
just tested it, nop, no good, sad.
Hi guys, I'm trying to deploy different instances of HDInsight ... but I'm facing an issue since for some of them we would like to link x number of Storage Accounts of for others Y ... I was planning to have an array with the X/Y storage accounts and pass the array with "Take" function ... but one of the properties for the SAs is the Key value ....... running out of ideas :S
The functions in the template language come in two flavors - compile time functions and runtime functions. reference and listKeys are both runtime functions, and are excluded from variables; only compile time functions are supported. . .
Can variables be expanded to allow for compile time functions?
Compile time functions are already supported in variables. Runtime functions are not.
OK. Can variables be expanded to allow for runtime time functions?
Perhaps - we will add this to the list of template enhancements.
@rjmax I too would like the ability to have it process run-time functions. I have to use the same key repeatedly in my template so it would be nice to be able to type out the listkeys function once and save it to a variable then use that much shorter variable repeatedly in the template.
@rjmax I want this so I can append a list of application settings to functionApps on creation. FunctionApps require a storage device resource entry(that uses listKeys), and I need to append a variable array of application settings to those appSettings. Is there any other area where we could concat/union the values together?
Please allow runtime functions to variables section.
Please allow runtime functions to variables section
Please support this feature. Otherwise ARM templates for Azure Functions look horrendously repetitive as seen here https://github.com/Azure/azure-quickstart-templates/blob/f1b49a0ddda3073e175133ba17f016408a7dc7d8/101-function-app-create-dynamic/azuredeploy.json#L68
"variables": {
"storageAccountKey": "[listKeys(resourceId('Microsoft.Storage/storageAccounts/mystorageaccount)),'2015-06-15').key1]"
}
It's not just a question of supporting the listKeys
function: We also need delayed evaluation, right? The mystorageaccount
may not exist yet (In the typical case where one ARM template creates your whole app)
so whats the issue? reference function or dependsOn do that, why cant this be done? especially when we take into account the fact that listKeys is actually being displayed like a separate resource being created during the deployment. I dont see any problem with that. why make life harder?
@ishepherd ARM templates create dependent resources in order. The dependsOn
or reference
value is how you would define that. So if a Web App relied on Azure Storage, then the Web App would add a dependsOn
and point it at the Storage account. Storage would then be created first and the key would be available to the Web App. So we already have, what you call, delayed evaluation.
@MisinformedDNA right, but this issue is about using listKeys in variables.
I doubt reference
(to not-created-yet resource) is supported in variables section. Let me know if I'm wrong.
I missed understood your comment. But yea, the whole point of this thread is runtime (or delayed) evaluation.
It's still unavailable. Any workarounds?
Boo. Using variables that include connection strings would be nice to simplify my ARM template. Please consider adding support for listKeys in the variables section.
@d1mnewz use nested deployments. and it works in general. if something doesnt work. you (most likely) can workaround with a nested deployment.
Any news on supporting this in variables
?
It seems very hard to achieve this request, variables will be compiled in the compile phase, at that time resources referenced by listKeys was not provisioned yet, so it cants retrieve the Object of the resources, as well all the properties of the Object
@mingtwan They don't have to be compiled at compile-time, that's just what's currently implemented. Azure Pipelines has the concept of expressions that can be evaluated at parse-time or run-time. There's no reason that couldn't be supported here as well.
I also hope they will implement this request as soon as possible so that our template will not be so ugly.
I can give you a reason why I faced a need to have runtime functions available in variables section. For every app service or azure function in arm template I have a bunch of properties eg: ApplicationInsights key or StorageAccount key which are created within ARM template so I use reference or listKeys function to retrieve values to set to the appSettings. And also I have a bunch of app settings variables from the code (app.settings.json or local.settings.json files). What I am about to achieve is to pass all appsettings variables in one array and apply it to the site together with pre-defined "infrastructure" settings. That gives a possibility to create a general ARM template for every function or app service I develop and then just change values in parameters files. No, on every additional property added to the app I need to add a new parameter to ARM template to pass. To the code:
"parameters": {
"storageAccountName": {
"type": "string",
"metadata": {
"description": "Name for storage account for all functions in Resource Group"
}
},
"appSettings": {
"type": "array",
"metadata": {
"description": "From local.settings.json."
}
}
}
"variables": {
"storageAccountid": "[concat(resourceGroup().id,'/providers/','Microsoft.Storage/storageAccounts/', parameters('storageAccountName'))]",
"functionWorkerRuntime": "[parameters('runtime')]",
"appInsightsInstrumentationKey": {
"name": "ApplicationInsights__InstrumentationKey",
"value": "[reference(concat('Microsoft.Insights/components/' , variables('applicationInsightsName')), '2015-05-01').InstrumentationKey]"
},
"AzureWebJobsDashboard": {
"name": "AzureWebJobsDashboard",
"value": "[concat('DefaultEndpointsProtocol=https;AccountName=', parameters('storageAccountName'), ';AccountKey=', listKeys(variables('storageAccountid'),'2015-05-01-preview').key1)]"
},
"AzureWebJobsStorage": {
"name": "AzureWebJobsStorage",
"value": "[concat('DefaultEndpointsProtocol=https;AccountName=', parameters('storageAccountName'), ';AccountKey=', listKeys(variables('storageAccountid'),'2015-05-01-preview').key1)]"
},
"allAppSettings": "[concat(createArray(variables('appInsightsInstrumentationKey'),variables('AzureWebJobsDashboard'), variables('AzureWebJobsStorage')), parameters('appSettings'))]"
}
and then:
"siteConfig": {
"copy": [
{
"name": "appSettings",
"count": "[length(variables('allAppSettings'))]",
"input": {
"name": "[variables('allAppSettings')[copyIndex('appSettings')].name]",
"value": "[variables('allAppSettings')[copyIndex('appSettings')].value)]"
}
}
]
}
Any update on this?
Seems that this also does not work for listAccountSas
. I need this used in multiple places in a master template that references a bunch of other templates in a storage account. Would be nice to have the key defined in one place, variables
.