From 0f6c9c41d9517da9cc969242325d6b11bacb8672 Mon Sep 17 00:00:00 2001 From: hezijie Date: Wed, 20 Sep 2023 12:29:30 +0800 Subject: [PATCH] add mongodb connection string for azurerm_cosmosdb_account resource --- .../cosmos/cosmosdb_account_resource.go | 36 ++++++++++++++++--- .../cosmosdb_mongo_database_resource_test.go | 12 +++++++ website/docs/r/cosmosdb_account.html.markdown | 16 +++++++++ 3 files changed, 60 insertions(+), 4 deletions(-) diff --git a/internal/services/cosmos/cosmosdb_account_resource.go b/internal/services/cosmos/cosmosdb_account_resource.go index 0895e96c1e0b..f24fbbd52b8f 100644 --- a/internal/services/cosmos/cosmosdb_account_resource.go +++ b/internal/services/cosmos/cosmosdb_account_resource.go @@ -40,10 +40,14 @@ import ( var CosmosDbAccountResourceName = "azurerm_cosmosdb_account" var connStringPropertyMap = map[string]string{ - "Primary SQL Connection String": "primary_sql_connection_string", - "Secondary SQL Connection String": "secondary_sql_connection_string", - "Primary Read-Only SQL Connection String": "primary_readonly_sql_connection_string", - "Secondary Read-Only SQL Connection String": "secondary_readonly_sql_connection_string", + "Primary SQL Connection String": "primary_sql_connection_string", + "Secondary SQL Connection String": "secondary_sql_connection_string", + "Primary Read-Only SQL Connection String": "primary_readonly_sql_connection_string", + "Secondary Read-Only SQL Connection String": "secondary_readonly_sql_connection_string", + "Primary MongoDB Connection String": "primary_mongodb_connection_string", + "Secondary MongoDB Connection String": "secondary_mongodb_connection_string", + "Primary Read-Only MongoDB Connection String": "primary_readonly_mongodb_connection_string", + "Secondary Read-Only MongoDB Connection String": "secondary_readonly_mongodb_connection_string", } type databaseAccountCapabilities string @@ -677,6 +681,30 @@ func resourceCosmosDbAccount() *pluginsdk.Resource { Sensitive: true, }, + "primary_mongodb_connection_string": { + Type: pluginsdk.TypeString, + Computed: true, + Sensitive: true, + }, + + "secondary_mongodb_connection_string": { + Type: pluginsdk.TypeString, + Computed: true, + Sensitive: true, + }, + + "primary_readonly_mongodb_connection_string": { + Type: pluginsdk.TypeString, + Computed: true, + Sensitive: true, + }, + + "secondary_readonly_mongodb_connection_string": { + Type: pluginsdk.TypeString, + Computed: true, + Sensitive: true, + }, + "tags": tags.Schema(), }, } diff --git a/internal/services/cosmos/cosmosdb_mongo_database_resource_test.go b/internal/services/cosmos/cosmosdb_mongo_database_resource_test.go index 8ecb42b9bb5b..50b3d7a1055a 100644 --- a/internal/services/cosmos/cosmosdb_mongo_database_resource_test.go +++ b/internal/services/cosmos/cosmosdb_mongo_database_resource_test.go @@ -28,6 +28,7 @@ func TestAccCosmosDbMongoDatabase_basic(t *testing.T) { Config: r.basic(data), Check: acceptance.ComposeAggregateTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), + checkAccCosmosDBAccount_mongodb("azurerm_cosmosdb_account.test"), ), }, data.ImportStep(), @@ -43,6 +44,7 @@ func TestAccCosmosDbMongoDatabase_complete(t *testing.T) { Config: r.complete(data), Check: acceptance.ComposeAggregateTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), + checkAccCosmosDBAccount_mongodb("azurerm_cosmosdb_account.test"), ), }, data.ImportStep(), @@ -90,6 +92,7 @@ func TestAccCosmosDbMongoDatabase_serverless(t *testing.T) { Config: r.serverless(data), Check: acceptance.ComposeAggregateTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), + checkAccCosmosDBAccount_mongodb("azurerm_cosmosdb_account.test"), ), }, data.ImportStep(), @@ -161,3 +164,12 @@ resource "azurerm_cosmosdb_mongo_database" "test" { } `, CosmosDBAccountResource{}.capabilities(data, documentdb.DatabaseAccountKindMongoDB, []string{"EnableServerless", "mongoEnableDocLevelTTL", "EnableMongo"}), data.RandomInteger) } + +func checkAccCosmosDBAccount_mongodb(resourceName string) acceptance.TestCheckFunc { + return acceptance.ComposeTestCheckFunc( + check.That(resourceName).Key("primary_mongodb_connection_string").Exists(), + check.That(resourceName).Key("secondary_mongodb_connection_string").Exists(), + check.That(resourceName).Key("primary_readonly_mongodb_connection_string").Exists(), + check.That(resourceName).Key("secondary_readonly_mongodb_connection_string").Exists(), + ) +} diff --git a/website/docs/r/cosmosdb_account.html.markdown b/website/docs/r/cosmosdb_account.html.markdown index c6c3ad11646b..0a8103bbb33b 100644 --- a/website/docs/r/cosmosdb_account.html.markdown +++ b/website/docs/r/cosmosdb_account.html.markdown @@ -311,6 +311,22 @@ In addition to the Arguments listed above - the following Attributes are exporte * `connection_strings` - A list of connection strings available for this CosmosDB account. +* `primary_sql_connection_string` - Primary SQL connection string for the CosmosDB Account. + +* `secondary_sql_connection_string` - Secondary SQL connection string for the CosmosDB Account. + +* `primary_readonly_sql_connection_string` - Primary readonly SQL connection string for the CosmosDB Account. + +* `secondary_readonly_sql_connection_string` - Secondary readonly SQL connection string for the CosmosDB Account. + +* `primary_mongodb_connection_string` - Primary Mongodb connection string for the CosmosDB Account. + +* `secondary_mongodb_connection_string` - Secondary Mongodb connection string for the CosmosDB Account. + +* `primary_readonly_mongodb_connection_string` - Primary readonly Mongodb connection string for the CosmosDB Account. + +* `secondary_readonly_mongodb_connection_string` - Secondary readonly Mongodb connection string for the CosmosDB Account. + --- An `identity` block exports the following: