Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

define a cosmos DB connection string into an Azure function app_settings #15947

Closed
pchevallier opened this issue Mar 22, 2022 · 4 comments · Fixed by #17810
Closed

define a cosmos DB connection string into an Azure function app_settings #15947

pchevallier opened this issue Mar 22, 2022 · 4 comments · Fixed by #17810

Comments

@pchevallier
Copy link

I feel the need to document the use case where you need to link an azure function to the cosmos DB database using the connection string.

Assume you have declared a cosmosdb resource in your TF script like this

resource "azurerm_cosmosdb_account" "db" {
..
}

and now you want to define the connection string in you your azure function:

resource "azurerm_function_app" "function_name" {
  ..
  app_settings = {
     ....
     "cosmosdb_readwrite_primary_key"       = azurerm_cosmosdb_account.db.connection_strings[0],
     "cosmosdb_readwrite_secondary_key"  = azurerm_cosmosdb_account.db.connection_strings[1],
    }

So, obviously this is assuming the array respects the current following description by MSFT:
az cosmosdb keys list --type connection-strings

{
  "connectionStrings": [
    {
      "connectionString": "AccountEndpoint=https://<redacted>.documents.azure.com:443/;AccountKey=<redacted>",
      "description": "Primary SQL Connection String"
    },
    {
      "connectionString": "AccountEndpoint=https://<redacted>.documents.azure.com:443/;AccountKey=<redacted>",
      "description": "Secondary SQL Connection String"
    },
    {
      "connectionString": "AccountEndpoint=https://<redacted>.documents.azure.com:443/;AccountKey=<redacted>",
      "description": "Primary Read-Only SQL Connection String"
    },
    {
      "connectionString": "AccountEndpoint=https://<redacted>.documents.azure.com:443/;AccountKey=<redacted>",
      "description": "Secondary Read-Only SQL Connection String"
    }
  ]
}
@sinbai
Copy link
Contributor

sinbai commented Mar 25, 2022

@pchevallier thank you for opeing this issue. Per the description "A map of key-value pairs for App Settings and custom values." of app_settings in the terraform doc, I assume that your use case would like to define a map of key-value pairs for custom values about cosmos db connection string in app_settings property, right? If so, I don't think it is necessary to document a sample in terraform doc, as the key-value pairs could be any strings you would like to define. what do you think?

@pchevallier
Copy link
Author

@sinbai thank you for the follow up.
A generic solution could perhaps consists of referencing the type of connection string we want to use directly in the TF cosmosdb model.
Example:

app_settings = {
     ....
     "ex_cosmosdb_primary_key"     =  azurerm_cosmosdb_account.db.connection_strings.primary_key,
     "ex_cosmosdb_secondary_key"   = azurerm_cosmosdb_account.db.connection_strings.secondary_key

That would avoid any future inconsistency if the structure of the array were to be changed by MSFT.

@github-actions
Copy link

This functionality has been released in v3.28.0 of the Terraform Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

@github-actions
Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.