Search code examples
azureazure-resource-managerazure-bicepazure-app-configuration

Azure App Configuration Store - Setting label on keyvalues using Bicep


I'm trying to add values to an Azure App Configuration Store using Bicep. I have an issue where I add a label to a keyValue.

This is my module:

@description('Configuration Store Name')
param configurationStoreName string

@description('key prefix')
param prefix string

@description('key name')
param keyName string

@description('value')
param value string

@description('content type')
param contentType string = 'string'

@description('Deployment Environment')
param deploymentEnvironment string = 'dev'

resource configurationStore 'Microsoft.AppConfiguration/configurationStores@2021-10-01-    preview' existing = {
name: configurationStoreName
}

resource configurationStoreValue     'Microsoft.AppConfiguration/configurationStores/keyValues@2021-10-01-preview' = {
  name: '${prefix}:${keyName}'
  parent: configurationStore
  properties: {
    contentType: contentType
    value: value
    tags: {
      environment: deploymentEnvironment
    }
  }
}

There doesn't seem to be any way to add a label, which I want to do to enable filtering.

It can be done when creating KeyValues using the Azure Portal, therefore it should be possible using Bicep.

Am I missing something, or is this missing functionality from Bicep?


Solution

  • EDIT April 2022 The documentation has now been updated

    The keyValues resource's name is a combination of key and label. The key and label are joined by the $ delimiter. The label is optional. In the above example, the keyValues resource with name myKey creates a key-value without a label.

    Percent-encoding, also known as URL encoding, allows keys or labels to include characters that are not allowed in ARM template resource names. % is not an allowed character either, so ~ is used in its place. To correctly encode a name, follow these steps:

    1. Apply URL encoding
    2. Replace ~ with ~7E
    3. Replace % with ~

    For example, to create a key-value pair with key name AppName:DbEndpoint and label name Test, the resource name should be AppName~3ADbEndpoint$Test.

    I tried this approach and it works:

    @description('Configuration Store Name')
    param configurationStoreName string
    
    @description('key prefix')
    param prefix string
    
    @description('key name')
    param keyName string
    
    @description('value')
    param value string
    
    @description('label')
    param label string
    
    @description('content type')
    param contentType string = 'string'
    
    @description('Deployment Environment')
    param deploymentEnvironment string = 'dev'
    
    resource configurationStore 'Microsoft.AppConfiguration/configurationStores@2021-10-01-preview' existing = {
      name: configurationStoreName
    }
    
    var keyValueName = empty(label) ? '${prefix}:${keyName}' : '${prefix}:${keyName}$${label}'
    
    resource configurationStoreValue 'Microsoft.AppConfiguration/configurationStores/keyValues@2021-10-01-preview' = {
      name: keyValueName
      parent: configurationStore
      properties: {
        contentType: contentType
        value: value
        tags: {
          environment: deploymentEnvironment
        }
      }
    }