Suraj
Suraj

Reputation: 395

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.

Upvotes: 0

Views: 1322

Answers (2)

Nilesh Thakkar
Nilesh Thakkar

Reputation: 2895

In your template file, you can have the following to get the Redis Cache ConnectionString that your provisioned:

"outputs": {
    "RedisCacheConnectionString": {
      "type": "string",
      "value":"[concat(reference(parameters('redisCacheName')).hostName,':', reference(parameters('redisCacheName')).sslPort,',password=',listKeys(resourceId('Microsoft.Cache/redis', parameters('redisCacheName')), '2020-06-01').primaryKey,',ssl=True,abortConnect=False')]" 
    }
  }

This answer is inspired based on @bhargavi-annadevara's answer.

Upvotes: 0

Bhargavi Annadevara
Bhargavi Annadevara

Reputation: 5492

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.

Upvotes: 1

Related Questions