AppConfiguration icon indicating copy to clipboard operation
AppConfiguration copied to clipboard

Allow querying for multiple labels from ARM Template using listKeyValue

Open jasonbrisbin opened this issue 3 years ago • 14 comments

I have been exploring the integration of App Configuration with ARM templates. Ideally I would like to be able to query for the value of key with an array of labels, returning only the first matching value.

Example scenario: An overly simple example might be the following.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-08-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.9",
  "parameters": {
    "environment": {
      "type": "String",
      "defaultValue": "dev",
      "metadata": {
        "description": "This is the SDLC environment that is being deployed to."
      }
    }
  },
  "variables": {
    "keyVaultName":"[concat(parameters('environment'),'-keyvault01')]",
    "skuFamily": {
      "key": "/keyvault/sku/family",
      "label": ["[variables('keyVaultName')]","[parameters('environment')]", "default"]
    },
    "skuName": {
      "key": "/keyvault/sku/name",
      "label": ["[variables('keyVaultName')]","[parameters('environment')]", "default"]
    },
    "enableSoftDelete": { 
      "key": "/keyvault/enableSoftDelete",
      "label": ["[variables('keyVaultName')]","[parameters('environment')]", "default"]
      }
  },
  "resources": [
    {
      "type": "Microsoft.KeyVault/vaults",
      "apiVersion": "2016-10-01",
      "name": "[variables('keyVaultName')]",
      "location": "northcentral",
      "properties": {
        "sku": {
          "family": "[listKeyValue(resourceId('Microsoft.AppConfiguration/configurationStores', 'appConfig01'), '2019-10-01',variables('skuFamily')).value]",          
          "name": "[listKeyValue(resourceId('Microsoft.AppConfiguration/configurationStores', 'appConfig01'), '2019-10-01',variables('skuName')).value]"
        },
        "accessPolicies": [],
        "tenantId": "53a61a04-8224-4d62-b270-a5823ebeb33c",
        "enabledForDeployment": false,
        "enabledForDiskEncryption": false,
        "enabledForTemplateDeployment": false,
        "enableSoftDelete": "[listKeyValue(resourceId('Microsoft.AppConfiguration/configurationStores', 'appConfig01'), '2019-10-01',variables('enableSoftDelete')).value]"
      }
    }
  ]
}


You can see that I am querying for some configuration Keys for Sku and enableSoftDelete. I am ordering my array of labels from most specific to least in this case. Enabling something like this would allow me to:

  • Provide a default for everything (least specific).
    • All keyvaults will be deployed as standard
  • Allow for an overload based on environment (more specific).
    • All keyvaults in production will be deployed as premium
  • While also allowing me to handle an exception for a specific named instance (most specific).
    • This specific production keyvault should be standard.

jasonbrisbin avatar Sep 28 '20 13:09 jasonbrisbin

@jasonbrisbin sorry for the late response. We are moving away from the listKeyValue API. Instead, we introduced KeyValues as a child resource in the new version 2020-07-01-preview, so you can query key-values by the standard ARM reference. Please check out the documentation for more details.

https://docs.microsoft.com/en-us/azure/azure-app-configuration/quickstart-resource-manager

zhenlan avatar Oct 08 '20 19:10 zhenlan

@jasonbrisbin please let us know if you have further questions. Closing for now.

zhenlan avatar Oct 21 '20 21:10 zhenlan

I don't see where KeyValues would allow for querying a single key with multiple labels as I mentioned initially. Is that possible?

jasonbrisbin avatar Oct 21 '20 22:10 jasonbrisbin

@jasonbrisbin you will have to query (reference) each key+label individually.

zhenlan avatar Oct 21 '20 23:10 zhenlan

If a key and label is not found will it throw an error?

jasonbrisbin avatar Oct 22 '20 00:10 jasonbrisbin

I suppose referencing a key-value that does not exist will cause errors when running the template. @ZhijunZhao can you please confirm?

zhenlan avatar Oct 22 '20 21:10 zhenlan

@jasonbrisbin Yes, it would throw error like below.

C:\>az deployment group create -g test-resource-group --template-file app-config-kv-template.json
Deployment failed. Correlation ID: f4b71fb2-1ff2-4af3-9bd4-d5dd52bf4129. {
  "code": "EntityNotFound",
  "message": "The resource with id 'myKey$myLabel' was not found."
}

ZhijunZhao avatar Oct 23 '20 03:10 ZhijunZhao

The core problem then remains.

jasonbrisbin avatar Dec 14 '20 17:12 jasonbrisbin

@jasonbrisbin ARM template does not support querying of multiple labels at once. But, @ZhijunZhao, is there a way to achieve what @jasonbrisbin wanted: query for the value of key with an array of labels, returning only the first matching value using what we have today?

zhenlan avatar Dec 14 '20 23:12 zhenlan

@zhenlan I think what @jasonbrisbin has is a sound case. But we have to add an API to support this. We could improve the listKeyValue API with key-label array input. More discussion is needed.

ZhijunZhao avatar Dec 15 '20 06:12 ZhijunZhao

Can we reopen this? I don't know why it was closed and would very much like this capability.

jasonbrisbin avatar Mar 18 '21 17:03 jasonbrisbin

@jasonbrisbin sure, reopened. The listKeyValue API will not be continued in the new version. However, we need to figure out how to support the scenario via the 'KeyValue' resource.

zhenlan avatar Mar 19 '21 19:03 zhenlan

cc: @jimmyca15 @MSGaryWang

zhenlan avatar Mar 19 '21 19:03 zhenlan

Any updates on this enhancement?

jasonbrisbin avatar Apr 12 '21 14:04 jasonbrisbin