@@ -386,6 +386,50 @@ func TestAccResourceMongoDBAtlasAdvancedCluster_DefaultWrite(t *testing.T) {
386
386
})
387
387
}
388
388
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
+
389
433
func testAccCheckMongoDBAtlasAdvancedClusterExists (resourceName string , cluster * matlas.AdvancedCluster ) resource.TestCheckFunc {
390
434
return func (s * terraform.State ) error {
391
435
conn := testAccProvider .Meta ().(* MongoDBClient ).Atlas
@@ -422,6 +466,16 @@ func testAccCheckMongoDBAtlasAdvancedClusterAttributes(cluster *matlas.AdvancedC
422
466
}
423
467
}
424
468
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
+
425
479
func testAccCheckMongoDBAtlasAdvancedClusterDestroy (s * terraform.State ) error {
426
480
conn := testAccProvider .Meta ().(* MongoDBClient ).Atlas
427
481
@@ -666,3 +720,38 @@ resource "mongodbatlas_advanced_cluster" "test" {
666
720
` , projectID , name , * p .JavascriptEnabled , p .MinimumEnabledTLSProtocol , * p .NoTableScan ,
667
721
* p .OplogSizeMB , * p .SampleSizeBIConnector , * p .SampleRefreshIntervalBIConnector , p .DefaultReadConcern , p .DefaultWriteConcern )
668
722
}
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