Search code examples
azure-cosmosdbazure-cosmosdb-sqlapiazure-cosmosdb-tables

How to get Connection string of a cosmos DB created for table API in ARM template


I am trying to create a cosmos db account for table APIs and want to upload the connection string to a KV using ARM template.

I expect the connection string in this format:

DefaultEndpointsProtocol=https;AccountName=<<AccountName>>;AccountKey=<<Key>>;TableEndpoint=https://<<AccountName>>.table.cosmos.azure.com:443/;

I am using this:

[listConnectionStrings(resourceId('Microsoft.DocumentDB/databaseAccounts', parameters('globalCosmosDBName')), '2019-12-12').connectionStrings[0].connectionString]

But with the above I am getting a connections string like below:

AccountEndpoint=https://<<AccountName>>.documents.azure.com:443/;AccountKey==<<Key>>;

How can I get a connection string with the table endpoint?


Solution

  • Our RP does not return the legacy table connection string format. It only has the format you have below.

    I think the only way to do this is to use concat to build the string and use a combination of the reference and listKeys arm functions below.

    "[reference(resourceId('Microsoft.DocumentDb/databaseAccounts/', parameters('globalCosmosDBName'))).documentEndpoint]"
    
    "[listKeys(resourceId('Microsoft.DocumentDb/databaseAccounts', parameters('globalCosmosDBName')), '2020-04-01').primaryMasterKey]"
    

    Here is the complete concat function.

    “[concat(‘DefaultEndpointsProtocol=https;AccountName=’, [reference(resourceId('Microsoft.DocumentDb/databaseAccounts/', parameters('globalCosmosDBName'))).documentEndpoint], ‘;AccountKey=’, [listKeys(resourceId('Microsoft.DocumentDb/databaseAccounts', parameters('globalCosmosDBName')), '2020-04-01').primaryMasterKey], ‘;TableEndpoint=https://’, [reference(resourceId('Microsoft.DocumentDb/databaseAccounts/', parameters('globalCosmosDBName'))).documentEndpoint], ‘.table.cosmos.azure.com:443/;’]”