From 0bb6c634e3ee7c083af8216b1a947bec61a9232c Mon Sep 17 00:00:00 2001 From: coderGo93 Date: Tue, 6 Apr 2021 16:08:56 -0600 Subject: [PATCH] INTMDB-194: Added func to get db major version for testing (#427) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * test: added func to get db majorversion and use it to pass to config via parameter * test: deleted ebs volume config for testing Co-authored-by: Edgar López --- .../resource_mongodbatlas_cluster_test.go | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/mongodbatlas/resource_mongodbatlas_cluster_test.go b/mongodbatlas/resource_mongodbatlas_cluster_test.go index 9079063fca..3697ca2882 100644 --- a/mongodbatlas/resource_mongodbatlas_cluster_test.go +++ b/mongodbatlas/resource_mongodbatlas_cluster_test.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "log" + "net/http" "os" "testing" @@ -843,13 +844,15 @@ func TestAccResourceMongoDBAtlasCluster_tenant(t *testing.T) { name = fmt.Sprintf("test-acc-%s", acctest.RandString(10)) ) + dbMajorVersion := testAccGetMongoDBAtlasMajorVersion() + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckMongoDBAtlasClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccMongoDBAtlasClusterConfigTenant(projectID, name, "M2", "2"), + Config: testAccMongoDBAtlasClusterConfigTenant(projectID, name, "M2", "2", dbMajorVersion), Check: resource.ComposeTestCheckFunc( testAccCheckMongoDBAtlasClusterExists(resourceName, &cluster), testAccCheckMongoDBAtlasClusterAttributes(&cluster, name), @@ -879,6 +882,7 @@ func TestAccResourceMongoDBAtlasCluster_tenant_m5(t *testing.T) { resourceName := "mongodbatlas_cluster.tenant" projectID := os.Getenv("MONGODB_ATLAS_PROJECT_ID") name := fmt.Sprintf("test-acc-%s", acctest.RandString(10)) + dbMajorVersion := testAccGetMongoDBAtlasMajorVersion() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -886,7 +890,7 @@ func TestAccResourceMongoDBAtlasCluster_tenant_m5(t *testing.T) { CheckDestroy: testAccCheckMongoDBAtlasClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccMongoDBAtlasClusterConfigTenant(projectID, name, "M5", "5"), + Config: testAccMongoDBAtlasClusterConfigTenant(projectID, name, "M5", "5", dbMajorVersion), Check: resource.ComposeTestCheckFunc( testAccCheckMongoDBAtlasClusterExists(resourceName, &cluster), testAccCheckMongoDBAtlasClusterAttributes(&cluster, name), @@ -911,6 +915,13 @@ func testAccCheckMongoDBAtlasClusterImportStateIDFunc(resourceName string) resou } } +func testAccGetMongoDBAtlasMajorVersion() string { + conn, _ := matlas.New(http.DefaultClient, matlas.SetBaseURL(matlas.CloudURL)) + majorVersion, _, _ := conn.DefaultMongoDBMajorVersion.Get(context.Background()) + + return majorVersion +} + func testAccCheckMongoDBAtlasClusterExists(resourceName string, cluster *matlas.Cluster) resource.TestCheckFunc { return func(s *terraform.State) error { conn := testAccProvider.Meta().(*matlas.Client) @@ -982,7 +993,6 @@ func testAccMongoDBAtlasClusterConfigAWS(projectID, name string, backupEnabled, // Provider Settings "block" provider_name = "AWS" provider_disk_iops = 300 - provider_encrypt_ebs_volume = false provider_instance_size_name = "M30" provider_region_name = "EU_CENTRAL_1" } @@ -1216,7 +1226,7 @@ func testAccMongoDBAtlasClusterConfigGlobal(projectID, name, backupEnabled strin `, projectID, name, backupEnabled) } -func testAccMongoDBAtlasClusterConfigTenant(projectID, name, instanceSize, diskSize string) string { +func testAccMongoDBAtlasClusterConfigTenant(projectID, name, instanceSize, diskSize, majorDBVersion string) string { return fmt.Sprintf(` resource "mongodbatlas_cluster" "tenant" { project_id = "%s" @@ -1230,10 +1240,10 @@ func testAccMongoDBAtlasClusterConfigTenant(projectID, name, instanceSize, diskS provider_instance_size_name = "%s" //These must be the following values - mongo_db_major_version = "4.2" + mongo_db_major_version = "%s" auto_scaling_disk_gb_enabled = false } - `, projectID, name, diskSize, instanceSize) + `, projectID, name, diskSize, instanceSize, majorDBVersion) } func testAccMongoDBAtlasClusterConfigTenantUpdated(projectID, name string) string {