Sunday, January 8, 2023

Setting up App Config values with Bicep

There are often times where we need to setup a master configuration instance for the config values that might be referenced within pipelines. In such situations we can setup the initial configs such as environment name initially. 

First of all we will initialise a set of key value names. 

param keyValueNames array = [
  'appName$dev'
  'environmentType$dev'
  'Acr_Name$dev'
  'region$dev-${region}'
]

Text after $ sign reference to the label name of the config.

Next we can setup values as an array with same length.

var keyValueValues = [
  appName
  dev_Environment
  dev_ACRName
  region
]

Next we can do the setup of the App Configuration instance. 

resource configStore 'Microsoft.AppConfiguration/configurationStores@2022-05-01' = {
  name: configStoreName
  location: region
  tags:tags
  sku: {
    name: 'standard'
  }
}

Lastly we can iterate through the key value names and post values.

resource configStoreKeyValue
'Microsoft.AppConfiguration/configurationStores/keyValues@2022-05-01'
= [for (item, i) in keyValueNames: {
  parent: configStore
  name: item
  properties: {
    value: keyValueValues[i]
    contentType: contentType
    tags: tags
  }
}]


No comments:

Post a Comment