Search code examples
azureazure-resource-managerazure-rm-templateazure-app-configuration

Get Read only connection strings of App Configuration in ARM Template


Hi I want to add Application Config Read Only Connection string in ARM Template

"appSettingsShared": {
            "value": [
              {
                "name": "RedisCache:ConnectionString",
                "value": "[concat(variables('RedisCacheName'),'.redis.cache.windows.net:6380,abortConnect=false,ssl=true,password=', listKeys(resourceId('Microsoft.Cache/Redis', variables('RedisCacheName')), '2015-08-01').primaryKey)]"
              },
               {
                "name": "AppConfig:ConnectionString",
                "value": "???"
              }
            ]

I know how to do it using Azure CLI:

az appconfig credential list -g $resourceGroup   -n $appConfigName --query "([?name=='Primary Read Only'].connectionString)[0]" --output tsv

Any help is really appreciated.


Solution

  • You can use the listkeys template function to retrieve your configStore keys and connection strings. The implementation is similar to the Configuration Stores - List Keys API, which returns a response similar to:

    {
      "value": [
        {
          "id": "439AD01B4BE67DB1",
          "name": "Primary",
          "value": "000000000000000000000000000000000000000000000000000000",
          "connectionString": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
          "lastModified": "2018-04-24T16:30:54+00:00",
          "readOnly": false
        },
        {
          "id": "CB45E100456857B9",
          "name": "Secondary",
          "value": "000000000000000000000000000000000000000000000000000000",
          "connectionString": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
          "lastModified": "2018-04-24T16:30:54+00:00",
          "readOnly": false
        },
        {
          "id": "B3AC55B7E71431A9",
          "name": "Primary Read Only",
          "value": "000000000000000000000000000000000000000000000000000000",
          "connectionString": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
          "lastModified": "2018-04-24T16:30:54+00:00",
          "readOnly": true
        },
        {
          "id": "E2AF6A9A89DCC177",
          "name": "Secondary Read Only",
          "value": "000000000000000000000000000000000000000000000000000000",
          "connectionString": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
          "lastModified": "2018-04-24T16:30:54+00:00",
          "readOnly": true
        }
      ]
    }
    

    Since you want to access the Read-Only connection strings, you can access it in your ARM template as follows:

    "value": "[listKeys(resourceId('Microsoft.AppConfiguration/configurationStores', variables('configurationStore_name')), '2019-11-01-preview').value[2].connectionString]"
    

    This would get you the Primary Read Only connection string. Similarly, value[3].connectionString would retrieve the Secondary Read Only connection string.