azure-quickstart-templates icon indicating copy to clipboard operation
azure-quickstart-templates copied to clipboard

listKeys not supported in variable

Open gregjhogan opened this issue 8 years ago • 45 comments

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?

gregjhogan avatar Mar 30 '16 17:03 gregjhogan

Adding @ravbhatnagar @rjmax from the ARM team for this request

singhkays avatar Mar 30 '16 18:03 singhkays

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).

mjpearse avatar Jul 26 '16 05:07 mjpearse

Do we know if this is available now?

mani0070 avatar Nov 11 '16 08:11 mani0070

just tested it, nop, no good, sad.

4c74356b41 avatar Nov 12 '16 20:11 4c74356b41

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

jsburckhardt avatar May 08 '17 03:05 jsburckhardt

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. . .

rjmax avatar May 08 '17 18:05 rjmax

Can variables be expanded to allow for compile time functions?

MisinformedDNA avatar May 11 '17 20:05 MisinformedDNA

Compile time functions are already supported in variables. Runtime functions are not.

rjmax avatar May 16 '17 23:05 rjmax

OK. Can variables be expanded to allow for runtime time functions?

MisinformedDNA avatar May 18 '17 14:05 MisinformedDNA

Perhaps - we will add this to the list of template enhancements.

rjmax avatar May 22 '17 16:05 rjmax

@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.

leftler avatar Sep 08 '17 14:09 leftler

@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?

DaveKlassen avatar Oct 20 '17 16:10 DaveKlassen

Please allow runtime functions to variables section.

Shivu1042 avatar Nov 08 '17 06:11 Shivu1042

Please allow runtime functions to variables section

camhart avatar Feb 12 '18 17:02 camhart

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

syedhassaanahmed avatar Mar 01 '18 15:03 syedhassaanahmed

    "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)

ishepherd avatar May 08 '18 10:05 ishepherd

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?

4c74356b41 avatar May 08 '18 10:05 4c74356b41

@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 avatar May 08 '18 14:05 MisinformedDNA

@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.

ishepherd avatar May 08 '18 23:05 ishepherd

I missed understood your comment. But yea, the whole point of this thread is runtime (or delayed) evaluation.

MisinformedDNA avatar May 08 '18 23:05 MisinformedDNA

It's still unavailable. Any workarounds?

d1mnewz avatar Jul 11 '18 17:07 d1mnewz

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.

peterfelts avatar Nov 28 '18 19:11 peterfelts

@d1mnewz use nested deployments. and it works in general. if something doesnt work. you (most likely) can workaround with a nested deployment.

4c74356b41 avatar Nov 29 '18 09:11 4c74356b41

Any news on supporting this in variables?

abatishchev avatar Mar 13 '19 05:03 abatishchev

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-zz avatar Sep 10 '19 13:09 mingtwan-zz

@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.

MisinformedDNA avatar Sep 11 '19 21:09 MisinformedDNA

I also hope they will implement this request as soon as possible so that our template will not be so ugly.

mingtwan-zz avatar Sep 12 '19 02:09 mingtwan-zz

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)]"
                      }
                    }
                  ]                                     
            }

sergey-borysenko avatar Oct 07 '19 14:10 sergey-borysenko

Any update on this?

Lusey77 avatar Feb 10 '20 19:02 Lusey77

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.

spaelling avatar Feb 11 '20 06:02 spaelling