Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

listKeys not supported in variable #1503

Open
gregjhogan opened this issue Mar 30, 2016 · 45 comments
Open

listKeys not supported in variable #1503

gregjhogan opened this issue Mar 30, 2016 · 45 comments
Labels

Comments

@gregjhogan
Copy link

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?

@singhkays
Copy link
Contributor

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

@mjpearse
Copy link

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

@mani0070
Copy link
Contributor

Do we know if this is available now?

@4c74356b41
Copy link

just tested it, nop, no good, sad.

@jsburckhardt
Copy link
Contributor

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

@rjmax
Copy link

rjmax commented May 8, 2017

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

@MisinformedDNA
Copy link

Can variables be expanded to allow for compile time functions?

@rjmax
Copy link

rjmax commented May 16, 2017

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

@MisinformedDNA
Copy link

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

@rjmax
Copy link

rjmax commented May 22, 2017

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

@leftler
Copy link

leftler commented Sep 8, 2017

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

@DaveKlassen
Copy link

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

@Shivu1042
Copy link

Please allow runtime functions to variables section.

@camhart
Copy link

camhart commented Feb 12, 2018

Please allow runtime functions to variables section

@syedhassaanahmed
Copy link

syedhassaanahmed commented Mar 1, 2018

Please support this feature. Otherwise ARM templates for Azure Functions look horrendously repetitive as seen here

"value": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('storageAccountName'), ';AccountKey=', listKeys(variables('storageAccountid'),'2015-05-01-preview').key1)]"

@ishepherd
Copy link

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

@4c74356b41
Copy link

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?

@MisinformedDNA
Copy link

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

@ishepherd
Copy link

ishepherd commented May 8, 2018

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

@MisinformedDNA
Copy link

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

@d1mnewz
Copy link

d1mnewz commented Jul 11, 2018

It's still unavailable. Any workarounds?

@peterfelts
Copy link

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.

@4c74356b41
Copy link

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

@abatishchev
Copy link
Contributor

Any news on supporting this in variables?

@mingtwan-zz
Copy link

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

@MisinformedDNA
Copy link

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

@mingtwan-zz
Copy link

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

@sergey-borysenko
Copy link

sergey-borysenko commented Oct 7, 2019

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

@Lusey77
Copy link

Lusey77 commented Feb 10, 2020

Any update on this?

@spaelling
Copy link

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.

@abatishchev
Copy link
Contributor

abatishchev commented Feb 11, 2020

@singhkays 4 years later and no proper response from the owning team. Please provide one.

Also please change the tag, from question to feature request (or something similar).

@abatishchev
Copy link
Contributor

@spaelling nested deployment is a viable/feasible workaround. Which works but leads to growing complexity without a good reason.

What we want? Referencing resources from variables. When we want it? 5 years ago!

@spaelling
Copy link

@spaelling nested deployment is a viable/feasible workaround. Which works but leads to growing complexity without a good reason.

What we want? Referencing resources from variables. When we want it? 5 years ago!

I am doing nested deployment. The linked templates are in a storage account, hence I need the SAS token. I know it adds complexity, but in this case the linked templates is needed in multiple other places. Necessary evil.

I will just be passing the SAS token as a parameter. Already need to pass an expiry date, because simple date functions is also not available.

@ishepherd
Copy link

@abatishchev I'm guessing the ARM engineers don't lurk here in the samples repo.
You could reach one of them direct (e.g. look for people who have given presentations on it)

@itpropro
Copy link

itpropro commented Nov 24, 2021

No updates to this issue from 2016 @rjmax?

@abatishchev
Copy link
Contributor

Tagging @bmoore-msft.

@bmoore-msft
Copy link
Collaborator

You can use listKeys (or any runtime function) in a variable in bicep.

@4c74356b41
Copy link

how does that work @bmoore-msft ?

@bmoore-msft
Copy link
Collaborator

The bicep compiler handles the variable replacement client side...

@mikeswain
Copy link

OMG this is so annoying - I just want to union a bunch of appSettings of which one contains a reference() but of course its not possible because you can't put reference() in a parameter or variable - appalling, along with most of the rest of ARM

@abatishchev
Copy link
Contributor

I just want to union a bunch of appSettings of which one contains a reference()

You can achieve that by leveraging nested/linked template with scope set to inner. Far from being simple and/or elegant but works.

@4c74356b41
Copy link

i dont think that is true @bmoore-msft? i my case it only allows to use resource.name or resource.id (which is a well-known property)

@mikeswain
Copy link

I just want to union a bunch of appSettings of which one contains a reference()

You can achieve that by leveraging nested/linked template with scope set to inner. Far from being simple and/or elegant but works.

Thanks yes - pretty clumsy though having to shift it all into a nested template, but probably the best solution if you've got a bunch of them. In the end I did it like this coz I only had one reference() I wanted to append, I stuck the resourceId bit into a variable first to shorten as much as poss, then use createArray/Obect to union in the reference() to that. Still ugly
`
"variables": {
"mysql": "[resourceId(subscription().subscriptionId,parameters('mysqlServer').resourceGroup,'Microsoft.DBforMySQL/flexibleServers', parameters('mysqlServer').name)]"
},
...
"appSettings": "[union(createArray(createObject('name','MYSQL_HOST','value',reference(variables('mysql'),'2021-05-01').fullyQualifiedDomainName)),parameters('appSettings'),parameters('extraAppSettings'))]",

`

@bmoore-msft
Copy link
Collaborator

i dont think that is true @bmoore-msft? i my case it only allows to use resource.name or resource.id (which is a well-known property)

If what is true? (with resource.id sounds like you're in bicep territory?)

@4c74356b41
Copy link

You can use listKeys (or any runtime function) in a variable in bicep.

this, ie my example:

var permissionsList = [ // make sure we use resource.property here so we depend on the resources in the iterator
  {
    scope: '${subscription().id}/resourceGroups/MC_${names.aks}_${names.aks}_${resourceGroup().location}'
    roleDefinitionId: 'b24988ac-6180-42a0-ab88-20f7382dd24c'
    principalId: aks.id << won't allow me to use aks.properties.identityProfile.kubeletidentity.objectId 
  }
  {
   omitted
  }
  {
   omitted
  }
  {
   omitted
  }
]
...
resource ResourceRoleAssignment 'Microsoft.Resources/deployments@2021-04-01' = [for item in permissionsList: {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests