From 94fba5ab2ec37d2cf82f294ba7c970729048658b Mon Sep 17 00:00:00 2001 From: neil-yechenwei Date: Mon, 9 Dec 2024 14:35:22 +0800 Subject: [PATCH 1/4] azurerm_mongo_cluster - remove the check logic for administrator_password --- .../mongocluster/mongo_cluster_resource.go | 4 ---- .../mongocluster/mongo_cluster_resource_test.go | 15 +++++++++++---- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/internal/services/mongocluster/mongo_cluster_resource.go b/internal/services/mongocluster/mongo_cluster_resource.go index eff72f9796c4..10b86df24d92 100644 --- a/internal/services/mongocluster/mongo_cluster_resource.go +++ b/internal/services/mongocluster/mongo_cluster_resource.go @@ -488,10 +488,6 @@ func (r MongoClusterResource) CustomizeDiff() sdk.ResourceFunc { return fmt.Errorf("`administrator_username` is required when `create_mode` is %s", string(mongoclusters.CreateModeDefault)) } - if state.AdministratorPassword == "" { - return fmt.Errorf("`administrator_password` is required when `create_mode` is %s", string(mongoclusters.CreateModeDefault)) - } - if state.ComputeTier == "" { return fmt.Errorf("`compute_tier` is required when `create_mode` is %s", string(mongoclusters.CreateModeDefault)) } diff --git a/internal/services/mongocluster/mongo_cluster_resource_test.go b/internal/services/mongocluster/mongo_cluster_resource_test.go index 9585f60b4b72..5fa72c291024 100644 --- a/internal/services/mongocluster/mongo_cluster_resource_test.go +++ b/internal/services/mongocluster/mongo_cluster_resource_test.go @@ -21,9 +21,9 @@ type MongoClusterResource struct{} func TestAccMongoClusterFreeTier(t *testing.T) { acceptance.RunTestsInSequence(t, map[string]map[string]func(t *testing.T){ "freeTier": { // Run tests in sequence since each subscription is limited to one free tier cluster per region and free tier is currently only available in South India. - "basic": testAccMongoCluster_basic, - "update": testAccMongoCluster_update, - "import": testAccMongoCluster_requiresImport, + "basic": testAccMongoCluster_basic, + //"update": testAccMongoCluster_update, + //"import": testAccMongoCluster_requiresImport, }, }) } @@ -119,12 +119,19 @@ func (r MongoClusterResource) basic(data acceptance.TestData) string { return fmt.Sprintf(` %s +resource "random_string" "test" { + length = 8 + numeric = true + upper = true + lower = true +} + resource "azurerm_mongo_cluster" "test" { name = "acctest-mc%d" resource_group_name = azurerm_resource_group.test.name location = azurerm_resource_group.test.location administrator_username = "adminTerraform" - administrator_password = "QAZwsx123" + administrator_password = random_string.test.result shard_count = "1" compute_tier = "Free" high_availability_mode = "Disabled" From f3a402015dd472303d651b99adb96171ac5d364b Mon Sep 17 00:00:00 2001 From: neil-yechenwei Date: Mon, 9 Dec 2024 14:41:14 +0800 Subject: [PATCH 2/4] update tc --- .../services/mongocluster/mongo_cluster_resource_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/services/mongocluster/mongo_cluster_resource_test.go b/internal/services/mongocluster/mongo_cluster_resource_test.go index 5fa72c291024..dc83711a9552 100644 --- a/internal/services/mongocluster/mongo_cluster_resource_test.go +++ b/internal/services/mongocluster/mongo_cluster_resource_test.go @@ -21,9 +21,9 @@ type MongoClusterResource struct{} func TestAccMongoClusterFreeTier(t *testing.T) { acceptance.RunTestsInSequence(t, map[string]map[string]func(t *testing.T){ "freeTier": { // Run tests in sequence since each subscription is limited to one free tier cluster per region and free tier is currently only available in South India. - "basic": testAccMongoCluster_basic, - //"update": testAccMongoCluster_update, - //"import": testAccMongoCluster_requiresImport, + "basic": testAccMongoCluster_basic, + "update": testAccMongoCluster_update, + "import": testAccMongoCluster_requiresImport, }, }) } From 40bfe91dae8b4611c0a44df5d0433d0434232bc1 Mon Sep 17 00:00:00 2001 From: neil-yechenwei Date: Mon, 9 Dec 2024 16:56:17 +0800 Subject: [PATCH 3/4] add random provider --- internal/acceptance/testcase.go | 4 ++++ .../mongocluster/mongo_cluster_resource_test.go | 10 +++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/internal/acceptance/testcase.go b/internal/acceptance/testcase.go index e9e218687ad1..f2907f547696 100644 --- a/internal/acceptance/testcase.go +++ b/internal/acceptance/testcase.go @@ -186,6 +186,10 @@ func (td TestData) externalProviders() map[string]resource.ExternalProvider { VersionConstraint: "=2.47.0", Source: "registry.terraform.io/hashicorp/azuread", }, + "random": { + VersionConstraint: "=3.6.3", + Source: "registry.terraform.io/hashicorp/random", + }, "time": { VersionConstraint: "=0.9.1", Source: "registry.terraform.io/hashicorp/time", diff --git a/internal/services/mongocluster/mongo_cluster_resource_test.go b/internal/services/mongocluster/mongo_cluster_resource_test.go index dc83711a9552..dced6835c588 100644 --- a/internal/services/mongocluster/mongo_cluster_resource_test.go +++ b/internal/services/mongocluster/mongo_cluster_resource_test.go @@ -21,9 +21,9 @@ type MongoClusterResource struct{} func TestAccMongoClusterFreeTier(t *testing.T) { acceptance.RunTestsInSequence(t, map[string]map[string]func(t *testing.T){ "freeTier": { // Run tests in sequence since each subscription is limited to one free tier cluster per region and free tier is currently only available in South India. - "basic": testAccMongoCluster_basic, - "update": testAccMongoCluster_update, - "import": testAccMongoCluster_requiresImport, + "basic": testAccMongoCluster_basic, + //"update": testAccMongoCluster_update, + //"import": testAccMongoCluster_requiresImport, }, }) } @@ -119,7 +119,7 @@ func (r MongoClusterResource) basic(data acceptance.TestData) string { return fmt.Sprintf(` %s -resource "random_string" "test" { +resource "random_password" "test" { length = 8 numeric = true upper = true @@ -131,7 +131,7 @@ resource "azurerm_mongo_cluster" "test" { resource_group_name = azurerm_resource_group.test.name location = azurerm_resource_group.test.location administrator_username = "adminTerraform" - administrator_password = random_string.test.result + administrator_password = random_password.test.result shard_count = "1" compute_tier = "Free" high_availability_mode = "Disabled" From 052a81a36d88152ec74c35e444ecd27738cf4ec6 Mon Sep 17 00:00:00 2001 From: neil-yechenwei Date: Mon, 9 Dec 2024 16:56:42 +0800 Subject: [PATCH 4/4] update tc --- .../services/mongocluster/mongo_cluster_resource_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/services/mongocluster/mongo_cluster_resource_test.go b/internal/services/mongocluster/mongo_cluster_resource_test.go index dced6835c588..8b9152932b77 100644 --- a/internal/services/mongocluster/mongo_cluster_resource_test.go +++ b/internal/services/mongocluster/mongo_cluster_resource_test.go @@ -21,9 +21,9 @@ type MongoClusterResource struct{} func TestAccMongoClusterFreeTier(t *testing.T) { acceptance.RunTestsInSequence(t, map[string]map[string]func(t *testing.T){ "freeTier": { // Run tests in sequence since each subscription is limited to one free tier cluster per region and free tier is currently only available in South India. - "basic": testAccMongoCluster_basic, - //"update": testAccMongoCluster_update, - //"import": testAccMongoCluster_requiresImport, + "basic": testAccMongoCluster_basic, + "update": testAccMongoCluster_update, + "import": testAccMongoCluster_requiresImport, }, }) }