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

azurerm_cosmosdb_account - Add mongodb connection strings #23331

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading