From 8ae8bc85bb9ca8751cf91e24da013426b235da82 Mon Sep 17 00:00:00 2001 From: Elena Xin <39109137+sinbai@users.noreply.github.com> Date: Tue, 29 Oct 2024 16:34:18 +0800 Subject: [PATCH] `azurerm_cosmosdb_account` - support new version of `mongo_server_version` (#27763) * support new values of mongo_server_version * fix comments * update test case --- .../cosmos/cosmosdb_account_resource.go | 13 ++--- .../cosmos/cosmosdb_account_resource_test.go | 53 +++++++++++++++++-- website/docs/r/cosmosdb_account.html.markdown | 2 +- 3 files changed, 54 insertions(+), 14 deletions(-) diff --git a/internal/services/cosmos/cosmosdb_account_resource.go b/internal/services/cosmos/cosmosdb_account_resource.go index 23efd070ac4e..7f16c3c61d2d 100644 --- a/internal/services/cosmos/cosmosdb_account_resource.go +++ b/internal/services/cosmos/cosmosdb_account_resource.go @@ -478,15 +478,10 @@ func resourceCosmosDbAccount() *pluginsdk.Resource { }, "mongo_server_version": { - Type: pluginsdk.TypeString, - Optional: true, - Computed: true, - ValidateFunc: validation.StringInSlice([]string{ - string(cosmosdb.ServerVersionThreePointTwo), - string(cosmosdb.ServerVersionThreePointSix), - string(cosmosdb.ServerVersionFourPointZero), - string(cosmosdb.ServerVersionFourPointTwo), - }, false), + Type: pluginsdk.TypeString, + Optional: true, + Computed: true, + ValidateFunc: validation.StringInSlice(cosmosdb.PossibleValuesForServerVersion(), false), }, "multiple_write_locations_enabled": { diff --git a/internal/services/cosmos/cosmosdb_account_resource_test.go b/internal/services/cosmos/cosmosdb_account_resource_test.go index fefcb5605d4e..593e105c88bb 100644 --- a/internal/services/cosmos/cosmosdb_account_resource_test.go +++ b/internal/services/cosmos/cosmosdb_account_resource_test.go @@ -1228,7 +1228,52 @@ func TestAccCosmosDBAccount_mongoVersion42(t *testing.T) { data.ResourceTest(t, r, []acceptance.TestStep{ { - Config: r.basicMongoDBVersion42(data, cosmosdb.DefaultConsistencyLevelSession), + Config: r.basicMongoDBVersion(data, cosmosdb.DefaultConsistencyLevelSession, "4.2"), + Check: acceptance.ComposeAggregateTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + +func TestAccCosmosDBAccount_mongoVersion50(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_cosmosdb_account", "test") + r := CosmosDBAccountResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.basicMongoDBVersion(data, cosmosdb.DefaultConsistencyLevelStrong, "5.0"), + Check: acceptance.ComposeAggregateTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + +func TestAccCosmosDBAccount_mongoVersion60(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_cosmosdb_account", "test") + r := CosmosDBAccountResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.basicMongoDBVersion(data, cosmosdb.DefaultConsistencyLevelSession, "6.0"), + Check: acceptance.ComposeAggregateTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + +func TestAccCosmosDBAccount_mongoVersion70(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_cosmosdb_account", "test") + r := CosmosDBAccountResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.basicMongoDBVersion(data, cosmosdb.DefaultConsistencyLevelSession, "7.0"), Check: acceptance.ComposeAggregateTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), @@ -3942,7 +3987,7 @@ resource "azurerm_cosmosdb_account" "test" { `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, string(consistency)) } -func (CosmosDBAccountResource) basicMongoDBVersion42(data acceptance.TestData, consistency cosmosdb.DefaultConsistencyLevel) string { +func (CosmosDBAccountResource) basicMongoDBVersion(data acceptance.TestData, consistency cosmosdb.DefaultConsistencyLevel, version string) string { return fmt.Sprintf(` provider "azurerm" { features {} @@ -3959,7 +4004,7 @@ resource "azurerm_cosmosdb_account" "test" { resource_group_name = azurerm_resource_group.test.name offer_type = "Standard" kind = "MongoDB" - mongo_server_version = "4.2" + mongo_server_version = "%s" capabilities { name = "EnableMongo" @@ -3974,7 +4019,7 @@ resource "azurerm_cosmosdb_account" "test" { failover_priority = 0 } } -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, string(consistency)) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, version, string(consistency)) } func (CosmosDBAccountResource) basicWithLocalAuthenticationDisabled(data acceptance.TestData, kind cosmosdb.DatabaseAccountKind, consistency cosmosdb.DefaultConsistencyLevel) string { diff --git a/website/docs/r/cosmosdb_account.html.markdown b/website/docs/r/cosmosdb_account.html.markdown index 64b2e38ac673..419a90f29a3f 100644 --- a/website/docs/r/cosmosdb_account.html.markdown +++ b/website/docs/r/cosmosdb_account.html.markdown @@ -170,7 +170,7 @@ The following arguments are supported: * `access_key_metadata_writes_enabled` - (Optional) Is write operations on metadata resources (databases, containers, throughput) via account keys enabled? Defaults to `true`. -* `mongo_server_version` - (Optional) The Server Version of a MongoDB account. Possible values are `4.2`, `4.0`, `3.6`, and `3.2`. +* `mongo_server_version` - (Optional) The Server Version of a MongoDB account. Possible values are `7.0`, `6.0`, `5.0`, `4.2`, `4.0`, `3.6`, and `3.2`. * `network_acl_bypass_for_azure_services` - (Optional) If Azure services can bypass ACLs. Defaults to `false`.