@@ -40,13 +40,16 @@ func TestAccClusterAdvancedCluster_basicTenant(t *testing.T) {
4040 resource .TestCheckResourceAttr (resourceName , "name" , clusterName ),
4141 resource .TestCheckResourceAttrSet (resourceName , "replication_specs.#" ),
4242 resource .TestCheckResourceAttrSet (resourceName , "replication_specs.0.region_configs.#" ),
43- resource .TestCheckResourceAttrSet (resourceName , "termination_protection_enabled" ),
43+ resource .TestCheckResourceAttr (resourceName , "termination_protection_enabled" , "false" ),
44+ resource .TestCheckResourceAttr (resourceName , "global_cluster_self_managed_sharding" , "false" ),
4445 resource .TestCheckResourceAttr (dataSourceName , "name" , clusterName ),
4546 resource .TestCheckResourceAttr (dataSourceName , "termination_protection_enabled" , "false" ),
47+ resource .TestCheckResourceAttr (dataSourceName , "global_cluster_self_managed_sharding" , "false" ),
4648 resource .TestCheckResourceAttrSet (dataSourcePluralName , "results.#" ),
4749 resource .TestCheckResourceAttrSet (dataSourcePluralName , "results.0.replication_specs.#" ),
4850 resource .TestCheckResourceAttrSet (dataSourcePluralName , "results.0.name" ),
4951 resource .TestCheckResourceAttrSet (dataSourcePluralName , "results.0.termination_protection_enabled" ),
52+ resource .TestCheckResourceAttrSet (dataSourcePluralName , "results.0.global_cluster_self_managed_sharding" ),
5053 ),
5154 },
5255 {
@@ -58,12 +61,16 @@ func TestAccClusterAdvancedCluster_basicTenant(t *testing.T) {
5861 resource .TestCheckResourceAttrSet (resourceName , "replication_specs.#" ),
5962 resource .TestCheckResourceAttrSet (resourceName , "replication_specs.0.region_configs.#" ),
6063 resource .TestCheckResourceAttr (resourceName , "labels.#" , "0" ),
64+ resource .TestCheckResourceAttr (resourceName , "termination_protection_enabled" , "false" ),
65+ resource .TestCheckResourceAttr (resourceName , "global_cluster_self_managed_sharding" , "false" ),
6166 resource .TestCheckResourceAttr (dataSourceName , "name" , clusterNameUpdated ),
6267 resource .TestCheckResourceAttr (dataSourceName , "termination_protection_enabled" , "false" ),
68+ resource .TestCheckResourceAttr (dataSourceName , "global_cluster_self_managed_sharding" , "false" ),
6369 resource .TestCheckResourceAttrSet (dataSourcePluralName , "results.#" ),
6470 resource .TestCheckResourceAttrSet (dataSourcePluralName , "results.0.replication_specs.#" ),
6571 resource .TestCheckResourceAttrSet (dataSourcePluralName , "results.0.name" ),
6672 resource .TestCheckResourceAttrSet (dataSourcePluralName , "results.0.termination_protection_enabled" ),
73+ resource .TestCheckResourceAttrSet (dataSourcePluralName , "results.0.global_cluster_self_managed_sharding" ),
6774 ),
6875 },
6976 {
@@ -547,11 +554,9 @@ func TestAccClusterAdvancedClusterConfig_replicationSpecsAnalyticsAutoScaling(t
547554
548555func TestAccClusterAdvancedClusterConfig_replicationSpecsAndShardUpdating (t * testing.T ) {
549556 var (
550- orgID = os .Getenv ("MONGODB_ATLAS_ORG_ID" )
551- projectName = acc .RandomProjectName ()
552- clusterName = acc .RandomClusterName () // No ProjectIDExecution to avoid cross-region limits because multi-region
553- numShards = "1"
554- numShardsUpdated = "2"
557+ orgID = os .Getenv ("MONGODB_ATLAS_ORG_ID" )
558+ projectName = acc .RandomProjectName () // No ProjectIDExecution to avoid cross-region limits because multi-region
559+ clusterName = acc .RandomClusterName ()
555560 )
556561
557562 resource .ParallelTest (t , resource.TestCase {
@@ -560,21 +565,27 @@ func TestAccClusterAdvancedClusterConfig_replicationSpecsAndShardUpdating(t *tes
560565 CheckDestroy : acc .CheckDestroyCluster ,
561566 Steps : []resource.TestStep {
562567 {
563- Config : configMultiZoneWithShards (orgID , projectName , clusterName , numShards , numShards ),
568+ Config : configMultiZoneWithShards (orgID , projectName , clusterName , 1 , 1 , false ),
564569 Check : resource .ComposeTestCheckFunc (
565570 checkExists (resourceName ),
566571 resource .TestCheckResourceAttr (resourceName , "name" , clusterName ),
567572 resource .TestCheckResourceAttr (resourceName , "replication_specs.0.num_shards" , "1" ),
568573 resource .TestCheckResourceAttr (resourceName , "replication_specs.1.num_shards" , "1" ),
574+ resource .TestCheckResourceAttr (dataSourceName , "name" , clusterName ),
575+ resource .TestCheckResourceAttr (dataSourceName , "replication_specs.0.num_shards" , "1" ),
576+ resource .TestCheckResourceAttr (dataSourceName , "replication_specs.1.num_shards" , "1" ),
569577 ),
570578 },
571579 {
572- Config : configMultiZoneWithShards (orgID , projectName , clusterName , numShardsUpdated , numShards ),
580+ Config : configMultiZoneWithShards (orgID , projectName , clusterName , 2 , 1 , false ),
573581 Check : resource .ComposeTestCheckFunc (
574582 checkExists (resourceName ),
575583 resource .TestCheckResourceAttr (resourceName , "name" , clusterName ),
576584 resource .TestCheckResourceAttr (resourceName , "replication_specs.0.num_shards" , "2" ),
577585 resource .TestCheckResourceAttr (resourceName , "replication_specs.1.num_shards" , "1" ),
586+ resource .TestCheckResourceAttr (dataSourceName , "name" , clusterName ),
587+ resource .TestCheckResourceAttr (dataSourceName , "replication_specs.0.num_shards" , "2" ),
588+ resource .TestCheckResourceAttr (dataSourceName , "replication_specs.1.num_shards" , "1" ),
578589 ),
579590 },
580591 },
@@ -656,6 +667,53 @@ func TestAccClusterAdvancedCluster_withTags(t *testing.T) {
656667 })
657668}
658669
670+ func TestAccClusterAdvancedClusterConfig_selfManagedSharding (t * testing.T ) {
671+ var (
672+ orgID = os .Getenv ("MONGODB_ATLAS_ORG_ID" )
673+ projectName = acc .RandomProjectName () // No ProjectIDExecution to avoid cross-region limits because multi-region
674+ clusterName = acc .RandomClusterName ()
675+ )
676+
677+ resource .ParallelTest (t , resource.TestCase {
678+ PreCheck : func () { acc .PreCheckBasic (t ) },
679+ ProtoV6ProviderFactories : acc .TestAccProviderV6Factories ,
680+ CheckDestroy : acc .CheckDestroyCluster ,
681+ Steps : []resource.TestStep {
682+ {
683+ Config : configMultiZoneWithShards (orgID , projectName , clusterName , 1 , 1 , true ),
684+ Check : resource .ComposeTestCheckFunc (
685+ checkExists (resourceName ),
686+ resource .TestCheckResourceAttr (resourceName , "global_cluster_self_managed_sharding" , "true" ),
687+ resource .TestCheckResourceAttr (dataSourceName , "global_cluster_self_managed_sharding" , "true" ),
688+ ),
689+ },
690+ {
691+ Config : configMultiZoneWithShards (orgID , projectName , clusterName , 1 , 1 , false ),
692+ ExpectError : regexp .MustCompile ("CANNOT_MODIFY_GLOBAL_CLUSTER_MANAGEMENT_SETTING" ),
693+ },
694+ },
695+ })
696+ }
697+
698+ func TestAccClusterAdvancedClusterConfig_selfManagedShardingIncorrectType (t * testing.T ) {
699+ var (
700+ projectID = acc .ProjectIDExecution (t )
701+ clusterName = acc .RandomClusterName ()
702+ )
703+
704+ resource .ParallelTest (t , resource.TestCase {
705+ PreCheck : func () { acc .PreCheckBasic (t ) },
706+ ProtoV6ProviderFactories : acc .TestAccProviderV6Factories ,
707+ CheckDestroy : acc .CheckDestroyCluster ,
708+ Steps : []resource.TestStep {
709+ {
710+ Config : configIncorrectTypeGobalClusterSelfManagedSharding (projectID , clusterName ),
711+ ExpectError : regexp .MustCompile ("CANNOT_SET_SELF_MANAGED_SHARDING_FOR_NON_GLOBAL_CLUSTER" ),
712+ },
713+ },
714+ })
715+ }
716+
659717func checkExists (resourceName string ) resource.TestCheckFunc {
660718 return func (s * terraform.State ) error {
661719 rs , ok := s .RootModule ().Resources [resourceName ]
@@ -788,6 +846,34 @@ func configSingleProvider(projectID, name string) string {
788846 ` , projectID , name )
789847}
790848
849+ func configIncorrectTypeGobalClusterSelfManagedSharding (projectID , name string ) string {
850+ return fmt .Sprintf (`
851+ resource "mongodbatlas_advanced_cluster" "test" {
852+ project_id = %[1]q
853+ name = %[2]q
854+
855+ cluster_type = "REPLICASET"
856+ global_cluster_self_managed_sharding = true # invalid, can only by used with GEOSHARDED clusters
857+
858+ replication_specs {
859+ region_configs {
860+ electable_specs {
861+ instance_size = "M10"
862+ node_count = 3
863+ }
864+ analytics_specs {
865+ instance_size = "M10"
866+ node_count = 1
867+ }
868+ provider_name = "AWS"
869+ priority = 7
870+ region_name = "US_WEST_2"
871+ }
872+ }
873+ }
874+ ` , projectID , name )
875+ }
876+
791877func configMultiCloud (orgID , projectName , name string ) string {
792878 return fmt .Sprintf (`
793879 resource "mongodbatlas_project" "cluster_project" {
@@ -1063,7 +1149,7 @@ func configReplicationSpecsAnalyticsAutoScaling(projectID, clusterName string, p
10631149 ` , projectID , clusterName , p .Compute .GetEnabled (), p .DiskGB .GetEnabled (), p .Compute .GetMaxInstanceSize ())
10641150}
10651151
1066- func configMultiZoneWithShards (orgID , projectName , name , numShardsFirstZone , numShardsSecondZone string ) string {
1152+ func configMultiZoneWithShards (orgID , projectName , name string , numShardsFirstZone , numShardsSecondZone int , selfManagedSharding bool ) string {
10671153 return fmt .Sprintf (`
10681154 resource "mongodbatlas_project" "cluster_project" {
10691155 org_id = %[1]q
@@ -1076,10 +1162,11 @@ func configMultiZoneWithShards(orgID, projectName, name, numShardsFirstZone, num
10761162 backup_enabled = false
10771163 mongo_db_major_version = "7.0"
10781164 cluster_type = "GEOSHARDED"
1165+ global_cluster_self_managed_sharding = %[6]t
10791166
10801167 replication_specs {
10811168 zone_name = "zone n1"
1082- num_shards = %[4]q
1169+ num_shards = %[4]d
10831170
10841171 region_configs {
10851172 electable_specs {
@@ -1098,7 +1185,7 @@ func configMultiZoneWithShards(orgID, projectName, name, numShardsFirstZone, num
10981185
10991186 replication_specs {
11001187 zone_name = "zone n2"
1101- num_shards = %[5]q
1188+ num_shards = %[5]d
11021189
11031190 region_configs {
11041191 electable_specs {
@@ -1115,5 +1202,10 @@ func configMultiZoneWithShards(orgID, projectName, name, numShardsFirstZone, num
11151202 }
11161203 }
11171204 }
1118- ` , orgID , projectName , name , numShardsFirstZone , numShardsSecondZone )
1205+
1206+ data "mongodbatlas_advanced_cluster" "test" {
1207+ project_id = mongodbatlas_advanced_cluster.test.project_id
1208+ name = mongodbatlas_advanced_cluster.test.name
1209+ }
1210+ ` , orgID , projectName , name , numShardsFirstZone , numShardsSecondZone , selfManagedSharding )
11191211}
0 commit comments