Skip to content

Commit ebbb5f0

Browse files
martinstibbeadmin
and
admin
authored
INTMDB-300: Advance Cluster resource ignoring the autoscaling options (#686)
* Advance Cluster resource ignoring the autoscaling options * Refactor and add additional test case * Add test parameters * Add support for autoscaling parameter tests * lint fix Co-authored-by: admin <[email protected]>
1 parent 6a4819a commit ebbb5f0

File tree

3 files changed

+102
-9
lines changed

3 files changed

+102
-9
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
*.dll
22
*.exe
33
.DS_Store
4+
.vscode
45
example.tf
56
terraform.tfplan
67
terraform.tfstate

mongodbatlas/resource_mongodbatlas_advanced_cluster.go

+12-9
Original file line numberDiff line numberDiff line change
@@ -825,27 +825,30 @@ func expandRegionConfigAutoScaling(tfList []interface{}) *matlas.AdvancedAutoSca
825825

826826
tfMap, _ := tfList[0].(map[string]interface{})
827827

828-
apiObject := &matlas.AdvancedAutoScaling{}
829-
apiObject2 := &matlas.DiskGB{}
830-
apiObject3 := &matlas.Compute{}
828+
advancedAutoScaling := &matlas.AdvancedAutoScaling{}
829+
diskGB := &matlas.DiskGB{}
830+
compute := &matlas.Compute{}
831831

832832
if v, ok := tfMap["disk_gb_enabled"]; ok {
833-
apiObject2.Enabled = pointy.Bool(v.(bool))
833+
diskGB.Enabled = pointy.Bool(v.(bool))
834834
}
835835
if v, ok := tfMap["compute_enabled"]; ok {
836-
apiObject3.Enabled = pointy.Bool(v.(bool))
836+
compute.Enabled = pointy.Bool(v.(bool))
837837
}
838838
if v, ok := tfMap["compute_scale_down_enabled"]; ok {
839-
apiObject3.ScaleDownEnabled = pointy.Bool(v.(bool))
839+
compute.ScaleDownEnabled = pointy.Bool(v.(bool))
840840
}
841841
if v, ok := tfMap["compute_min_instance_size"]; ok {
842-
apiObject3.MinInstanceSize = v.(string)
842+
compute.MinInstanceSize = v.(string)
843843
}
844844
if v, ok := tfMap["compute_max_instance_size"]; ok {
845-
apiObject3.MaxInstanceSize = v.(string)
845+
compute.MaxInstanceSize = v.(string)
846846
}
847847

848-
return apiObject
848+
advancedAutoScaling.DiskGB = diskGB
849+
advancedAutoScaling.Compute = compute
850+
851+
return advancedAutoScaling
849852
}
850853

851854
func flattenAdvancedReplicationSpec(ctx context.Context, apiObject *matlas.AdvancedReplicationSpec, tfMapObject map[string]interface{},

mongodbatlas/resource_mongodbatlas_advanced_cluster_test.go

+89
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,50 @@ func TestAccResourceMongoDBAtlasAdvancedCluster_DefaultWrite(t *testing.T) {
386386
})
387387
}
388388

389+
func TestAccMongoDBAtlasAdvancedClusterConfig_ReplicationSpecsAutoScaling(t *testing.T) {
390+
var (
391+
cluster matlas.AdvancedCluster
392+
resourceName = "mongodbatlas_advanced_cluster.test"
393+
projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID")
394+
rName = acctest.RandomWithPrefix("test-acc")
395+
rNameUpdated = acctest.RandomWithPrefix("test-acc")
396+
autoScaling = &matlas.AutoScaling{
397+
Compute: &matlas.Compute{Enabled: pointy.Bool(false), MaxInstanceSize: ""},
398+
DiskGBEnabled: pointy.Bool(true),
399+
}
400+
autoScalingUpdated = &matlas.AutoScaling{
401+
Compute: &matlas.Compute{Enabled: pointy.Bool(true), MaxInstanceSize: "M20"},
402+
DiskGBEnabled: pointy.Bool(true),
403+
}
404+
)
405+
406+
resource.ParallelTest(t, resource.TestCase{
407+
PreCheck: func() { testAccPreCheck(t) },
408+
ProviderFactories: testAccProviderFactories,
409+
CheckDestroy: testAccCheckMongoDBAtlasAdvancedClusterDestroy,
410+
Steps: []resource.TestStep{
411+
{
412+
Config: testAccMongoDBAtlasAdvancedClusterConfigReplicationSpecsAutoScaling(projectID, rName, autoScaling),
413+
Check: resource.ComposeTestCheckFunc(
414+
testAccCheckMongoDBAtlasAdvancedClusterExists(resourceName, &cluster),
415+
testAccCheckMongoDBAtlasAdvancedClusterAttributes(&cluster, rName),
416+
resource.TestCheckResourceAttrSet(resourceName, "replication_specs.0.region_configs.#"),
417+
testAccCheckMongoDBAtlasAdvancedClusterScaling(&cluster, *autoScaling.Compute.Enabled),
418+
),
419+
},
420+
{
421+
Config: testAccMongoDBAtlasAdvancedClusterConfigReplicationSpecsAutoScaling(projectID, rNameUpdated, autoScalingUpdated),
422+
Check: resource.ComposeTestCheckFunc(
423+
testAccCheckMongoDBAtlasAdvancedClusterExists(resourceName, &cluster),
424+
testAccCheckMongoDBAtlasAdvancedClusterAttributes(&cluster, rNameUpdated),
425+
resource.TestCheckResourceAttrSet(resourceName, "replication_specs.0.region_configs.#"),
426+
testAccCheckMongoDBAtlasAdvancedClusterScaling(&cluster, *autoScalingUpdated.Compute.Enabled),
427+
),
428+
},
429+
},
430+
})
431+
}
432+
389433
func testAccCheckMongoDBAtlasAdvancedClusterExists(resourceName string, cluster *matlas.AdvancedCluster) resource.TestCheckFunc {
390434
return func(s *terraform.State) error {
391435
conn := testAccProvider.Meta().(*MongoDBClient).Atlas
@@ -422,6 +466,16 @@ func testAccCheckMongoDBAtlasAdvancedClusterAttributes(cluster *matlas.AdvancedC
422466
}
423467
}
424468

469+
func testAccCheckMongoDBAtlasAdvancedClusterScaling(cluster *matlas.AdvancedCluster, computeEnabled bool) resource.TestCheckFunc {
470+
return func(s *terraform.State) error {
471+
if *cluster.ReplicationSpecs[0].RegionConfigs[0].AutoScaling.Compute.Enabled != computeEnabled {
472+
return fmt.Errorf("compute_enabled: %d", cluster.ReplicationSpecs[0].RegionConfigs[0].AutoScaling.Compute.Enabled)
473+
}
474+
475+
return nil
476+
}
477+
}
478+
425479
func testAccCheckMongoDBAtlasAdvancedClusterDestroy(s *terraform.State) error {
426480
conn := testAccProvider.Meta().(*MongoDBClient).Atlas
427481

@@ -666,3 +720,38 @@ resource "mongodbatlas_advanced_cluster" "test" {
666720
`, projectID, name, *p.JavascriptEnabled, p.MinimumEnabledTLSProtocol, *p.NoTableScan,
667721
*p.OplogSizeMB, *p.SampleSizeBIConnector, *p.SampleRefreshIntervalBIConnector, p.DefaultReadConcern, p.DefaultWriteConcern)
668722
}
723+
724+
func testAccMongoDBAtlasAdvancedClusterConfigReplicationSpecsAutoScaling(projectID, name string, p *matlas.AutoScaling) string {
725+
return fmt.Sprintf(`
726+
resource "mongodbatlas_advanced_cluster" "test" {
727+
project_id = %[1]q
728+
name = %[2]q
729+
cluster_type = "REPLICASET"
730+
mongo_db_major_version = "4.4"
731+
732+
replication_specs {
733+
region_configs {
734+
electable_specs {
735+
instance_size = "M10"
736+
node_count = 3
737+
}
738+
analytics_specs {
739+
instance_size = "M10"
740+
node_count = 1
741+
}
742+
auto_scaling {
743+
compute_enabled = %[3]t
744+
disk_gb_enabled = %[4]t
745+
compute_max_instance_size = %[5]q
746+
}
747+
provider_name = "AWS"
748+
priority = 7
749+
region_name = "US_EAST_1"
750+
}
751+
}
752+
753+
754+
}
755+
756+
`, projectID, name, *p.Compute.Enabled, *p.DiskGBEnabled, p.Compute.MaxInstanceSize)
757+
}

0 commit comments

Comments
 (0)