Skip to content

Commit

Permalink
add mongodb connection string for azurerm_cosmosdb_account resource (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
lonegunmanb committed Sep 20, 2023
1 parent 7e2a425 commit 41497e9
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 4 deletions.
36 changes: 32 additions & 4 deletions internal/services/cosmos/cosmosdb_account_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(),
},
}
Expand Down
12 changes: 12 additions & 0 deletions internal/services/cosmos/cosmosdb_mongo_database_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
)
}
16 changes: 16 additions & 0 deletions website/docs/r/cosmosdb_account.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 41497e9

Please sign in to comment.