@@ -40,13 +40,16 @@ func TestAccClusterAdvancedCluster_basicTenant(t *testing.T) {
40
40
resource .TestCheckResourceAttr (resourceName , "name" , clusterName ),
41
41
resource .TestCheckResourceAttrSet (resourceName , "replication_specs.#" ),
42
42
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" ),
44
45
resource .TestCheckResourceAttr (dataSourceName , "name" , clusterName ),
45
46
resource .TestCheckResourceAttr (dataSourceName , "termination_protection_enabled" , "false" ),
47
+ resource .TestCheckResourceAttr (dataSourceName , "global_cluster_self_managed_sharding" , "false" ),
46
48
resource .TestCheckResourceAttrSet (dataSourcePluralName , "results.#" ),
47
49
resource .TestCheckResourceAttrSet (dataSourcePluralName , "results.0.replication_specs.#" ),
48
50
resource .TestCheckResourceAttrSet (dataSourcePluralName , "results.0.name" ),
49
51
resource .TestCheckResourceAttrSet (dataSourcePluralName , "results.0.termination_protection_enabled" ),
52
+ resource .TestCheckResourceAttrSet (dataSourcePluralName , "results.0.global_cluster_self_managed_sharding" ),
50
53
),
51
54
},
52
55
{
@@ -58,12 +61,16 @@ func TestAccClusterAdvancedCluster_basicTenant(t *testing.T) {
58
61
resource .TestCheckResourceAttrSet (resourceName , "replication_specs.#" ),
59
62
resource .TestCheckResourceAttrSet (resourceName , "replication_specs.0.region_configs.#" ),
60
63
resource .TestCheckResourceAttr (resourceName , "labels.#" , "0" ),
64
+ resource .TestCheckResourceAttr (resourceName , "termination_protection_enabled" , "false" ),
65
+ resource .TestCheckResourceAttr (resourceName , "global_cluster_self_managed_sharding" , "false" ),
61
66
resource .TestCheckResourceAttr (dataSourceName , "name" , clusterNameUpdated ),
62
67
resource .TestCheckResourceAttr (dataSourceName , "termination_protection_enabled" , "false" ),
68
+ resource .TestCheckResourceAttr (dataSourceName , "global_cluster_self_managed_sharding" , "false" ),
63
69
resource .TestCheckResourceAttrSet (dataSourcePluralName , "results.#" ),
64
70
resource .TestCheckResourceAttrSet (dataSourcePluralName , "results.0.replication_specs.#" ),
65
71
resource .TestCheckResourceAttrSet (dataSourcePluralName , "results.0.name" ),
66
72
resource .TestCheckResourceAttrSet (dataSourcePluralName , "results.0.termination_protection_enabled" ),
73
+ resource .TestCheckResourceAttrSet (dataSourcePluralName , "results.0.global_cluster_self_managed_sharding" ),
67
74
),
68
75
},
69
76
{
@@ -547,11 +554,9 @@ func TestAccClusterAdvancedClusterConfig_replicationSpecsAnalyticsAutoScaling(t
547
554
548
555
func TestAccClusterAdvancedClusterConfig_replicationSpecsAndShardUpdating (t * testing.T ) {
549
556
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 ()
555
560
)
556
561
557
562
resource .ParallelTest (t , resource.TestCase {
@@ -560,21 +565,27 @@ func TestAccClusterAdvancedClusterConfig_replicationSpecsAndShardUpdating(t *tes
560
565
CheckDestroy : acc .CheckDestroyCluster ,
561
566
Steps : []resource.TestStep {
562
567
{
563
- Config : configMultiZoneWithShards (orgID , projectName , clusterName , numShards , numShards ),
568
+ Config : configMultiZoneWithShards (orgID , projectName , clusterName , 1 , 1 , false ),
564
569
Check : resource .ComposeTestCheckFunc (
565
570
checkExists (resourceName ),
566
571
resource .TestCheckResourceAttr (resourceName , "name" , clusterName ),
567
572
resource .TestCheckResourceAttr (resourceName , "replication_specs.0.num_shards" , "1" ),
568
573
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" ),
569
577
),
570
578
},
571
579
{
572
- Config : configMultiZoneWithShards (orgID , projectName , clusterName , numShardsUpdated , numShards ),
580
+ Config : configMultiZoneWithShards (orgID , projectName , clusterName , 2 , 1 , false ),
573
581
Check : resource .ComposeTestCheckFunc (
574
582
checkExists (resourceName ),
575
583
resource .TestCheckResourceAttr (resourceName , "name" , clusterName ),
576
584
resource .TestCheckResourceAttr (resourceName , "replication_specs.0.num_shards" , "2" ),
577
585
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" ),
578
589
),
579
590
},
580
591
},
@@ -656,6 +667,53 @@ func TestAccClusterAdvancedCluster_withTags(t *testing.T) {
656
667
})
657
668
}
658
669
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
+
659
717
func checkExists (resourceName string ) resource.TestCheckFunc {
660
718
return func (s * terraform.State ) error {
661
719
rs , ok := s .RootModule ().Resources [resourceName ]
@@ -788,6 +846,34 @@ func configSingleProvider(projectID, name string) string {
788
846
` , projectID , name )
789
847
}
790
848
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
+
791
877
func configMultiCloud (orgID , projectName , name string ) string {
792
878
return fmt .Sprintf (`
793
879
resource "mongodbatlas_project" "cluster_project" {
@@ -1063,7 +1149,7 @@ func configReplicationSpecsAnalyticsAutoScaling(projectID, clusterName string, p
1063
1149
` , projectID , clusterName , p .Compute .GetEnabled (), p .DiskGB .GetEnabled (), p .Compute .GetMaxInstanceSize ())
1064
1150
}
1065
1151
1066
- func configMultiZoneWithShards (orgID , projectName , name , numShardsFirstZone , numShardsSecondZone string ) string {
1152
+ func configMultiZoneWithShards (orgID , projectName , name string , numShardsFirstZone , numShardsSecondZone int , selfManagedSharding bool ) string {
1067
1153
return fmt .Sprintf (`
1068
1154
resource "mongodbatlas_project" "cluster_project" {
1069
1155
org_id = %[1]q
@@ -1076,10 +1162,11 @@ func configMultiZoneWithShards(orgID, projectName, name, numShardsFirstZone, num
1076
1162
backup_enabled = false
1077
1163
mongo_db_major_version = "7.0"
1078
1164
cluster_type = "GEOSHARDED"
1165
+ global_cluster_self_managed_sharding = %[6]t
1079
1166
1080
1167
replication_specs {
1081
1168
zone_name = "zone n1"
1082
- num_shards = %[4]q
1169
+ num_shards = %[4]d
1083
1170
1084
1171
region_configs {
1085
1172
electable_specs {
@@ -1098,7 +1185,7 @@ func configMultiZoneWithShards(orgID, projectName, name, numShardsFirstZone, num
1098
1185
1099
1186
replication_specs {
1100
1187
zone_name = "zone n2"
1101
- num_shards = %[5]q
1188
+ num_shards = %[5]d
1102
1189
1103
1190
region_configs {
1104
1191
electable_specs {
@@ -1115,5 +1202,10 @@ func configMultiZoneWithShards(orgID, projectName, name, numShardsFirstZone, num
1115
1202
}
1116
1203
}
1117
1204
}
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 )
1119
1211
}
0 commit comments