Create App Configuration using Bicep
Create App Configuration using Bicep

Create Azure App Configuration Service using Bicep

I have been writing about Azure App Configuration Service since past few days. The list of previous articles is given below.

We have created an instance of App Configuration Service and then we added couple of keys to the store. But we performed both of these operations via Azure Portal. This is not efficient. We may want to automate creation of the resource and addition of keys to the store. So, in this article, we are going to use Azure Bicep for creating the App Configuration Service instance.

Prerequisites

For following all steps in this article, we will need Azure Subscription. If you don’t have an Azure subscription, create a free account before you begin.

We are going to write script in Visual Studio Code. Hence you will need it installed on your machine. You will also need to ensure that the Bicep extension is installed.

What will we need in the script ?

Let’s create a new bicep file, app-config-service.bicep. In this file, we need to create the app configuration service and then we will add the key-value pairs.

For creating the app configuration service, we will need below mentioned parameters:

  • appConfigStoreName, the name of the app configuration service instance
  • location, specifying the region in which this resource should be created

We also need to specify the resource group, which can be specified while triggering the bicep module.

Now, let’s say we want to create couple of key-value pairs in the store. For the sake of this demo, let’s say we want to insert the below mentioned pairs:

Key = TestApi:GetEndpoint:Message, Value = Hello

Key = TestApi:PostEndpoint:Message, Value= Good Morning

We can add these key-value pairs in a JSON file, which contains collection of the key-value pairs. This JSON file path can be loaded using File Function and then we can loop over the collection to insert them one by one in the store.

We will need one resource element to create the new resource (i.e. app configuration service). Then, another resource element for adding the key-value pairs to existing app configuration service.

Once the execution is done, let’s say we want to provide connection string as output so that consuming application can use this output and configure it at right place.

Bicep File

We have discussed the theme of the bicep file in the previous section. The code snippet given below shows the contents of bicep file.

JSON File

The JSON file which is used in the bicep file shown in the code snippet given above, contains collection of key-value pairs. Each object has four properties:

  • key, which is the identifier for the setting
  • value, which is the value of the setting
  • contentType, to specify the content type of the value, so that it can be parsed correctly by the consumer. This is of string type.
  • tags, to specify the property name and values to be associated with the current key-value pair. This is a dictionary object

The code snippet given below shows the file. Each key has two tags, environment (value: dev) and region. The last key-value pair also specify a label in the key. The key identifier and label is separated by $ sign.

Please this file in the same directory where bicep file is located.

Deploy the Bicep File

We can use Azure CLI to deploy this bicep file. It will create a resource group first. Then it will deploy the bicep file. The third command will use the deployment name to query the outputs of the bicep file. The readonly connection string would be shown on the console. The last command is to verify that app configuration service is deployed.

Verify

We can login to Azure Portal and navigate to the resource group. Then select the Azure App Configuration Service instance. We can navigate to Operations -> Configuration explorer and then we can see that the three key-value pairs have been inserted.

Azure Portal – Verify the Azure App Configuration Service and Key Value Pairs

Wrapping Up

So, we have successfully created script to deploy Azure App Configuration Service instance. We also have inserted key-value pairs using the bicep file. You can find the code in my GitHub repository.

I hope you find this information helpful. Let mek now your thoughts.

Leave a Reply Cancel reply