@@ -103,7 +103,7 @@ func TestAccResourceMongoDBAtlasGlobalCluster_importBasic(t *testing.T) {
103
103
resource .Test (t , resource.TestCase {
104
104
PreCheck : func () { testAccPreCheck (t ) },
105
105
ProviderFactories : testAccProviderFactories ,
106
- CheckDestroy : testAccCheckMongoDBAtlasProjectIPAccessListDestroy ,
106
+ CheckDestroy : testAccCheckMongoDBAtlasGlobalClusterDestroy ,
107
107
Steps : []resource.TestStep {
108
108
{
109
109
Config : testAccMongoDBAtlasGlobalClusterConfig (projectID , name , "false" , "false" , "false" ),
@@ -119,6 +119,92 @@ func TestAccResourceMongoDBAtlasGlobalCluster_importBasic(t *testing.T) {
119
119
})
120
120
}
121
121
122
+ func TestAccResourceMongoDBAtlasGlobalCluster_database (t * testing.T ) {
123
+ var (
124
+ globalConfig matlas.GlobalCluster
125
+ resourceName = "mongodbatlas_global_cluster_config.test"
126
+ projectID = os .Getenv ("MONGODB_ATLAS_PROJECT_ID" )
127
+ name = acctest .RandomWithPrefix ("test-acc-global" )
128
+ )
129
+
130
+ customZone := `
131
+ custom_zone_mappings {
132
+ location = "US"
133
+ zone = "US"
134
+ }
135
+ custom_zone_mappings {
136
+ location = "IE"
137
+ zone = "EU"
138
+ }
139
+ custom_zone_mappings {
140
+ location = "DE"
141
+ zone = "DE"
142
+ }`
143
+ customZoneUpdated := `
144
+ custom_zone_mappings {
145
+ location = "US"
146
+ zone = "US"
147
+ }
148
+ custom_zone_mappings {
149
+ location = "IE"
150
+ zone = "EU"
151
+ }
152
+ custom_zone_mappings {
153
+ location = "DE"
154
+ zone = "DE"
155
+ }
156
+ custom_zone_mappings {
157
+ location = "JP"
158
+ zone = "JP"
159
+ }`
160
+
161
+ resource .Test (t , resource.TestCase {
162
+ PreCheck : func () { testAccPreCheck (t ) },
163
+ ProviderFactories : testAccProviderFactories ,
164
+ CheckDestroy : testAccCheckMongoDBAtlasGlobalClusterDestroy ,
165
+ Steps : []resource.TestStep {
166
+ {
167
+ Config : testAccMongoDBAtlasGlobalClusterWithDBConfig (projectID , name , "false" , customZone ),
168
+ Check : resource .ComposeTestCheckFunc (
169
+ testAccCheckMongoDBAtlasGlobalClusterExists (resourceName , & globalConfig ),
170
+ resource .TestCheckResourceAttrSet (resourceName , "managed_namespaces.#" ),
171
+ resource .TestCheckResourceAttrSet (resourceName , "custom_zone_mappings.#" ),
172
+ resource .TestCheckResourceAttrSet (resourceName , "custom_zone_mapping.%" ),
173
+ resource .TestCheckResourceAttrSet (resourceName , "custom_zone_mapping.US" ),
174
+ resource .TestCheckResourceAttrSet (resourceName , "custom_zone_mapping.IE" ),
175
+ resource .TestCheckResourceAttrSet (resourceName , "custom_zone_mapping.DE" ),
176
+ resource .TestCheckResourceAttr (resourceName , "cluster_name" , name ),
177
+ resource .TestCheckResourceAttr (resourceName , "project_id" , projectID ),
178
+ testAccCheckMongoDBAtlasGlobalClusterAttributes (& globalConfig , 5 ),
179
+ ),
180
+ },
181
+ {
182
+ Config : testAccMongoDBAtlasGlobalClusterWithDBConfig (projectID , name , "false" , customZoneUpdated ),
183
+ Check : resource .ComposeTestCheckFunc (
184
+ testAccCheckMongoDBAtlasGlobalClusterExists (resourceName , & globalConfig ),
185
+ resource .TestCheckResourceAttrSet (resourceName , "managed_namespaces.#" ),
186
+ resource .TestCheckResourceAttrSet (resourceName , "custom_zone_mappings.#" ),
187
+ resource .TestCheckResourceAttrSet (resourceName , "custom_zone_mapping.%" ),
188
+ resource .TestCheckResourceAttrSet (resourceName , "custom_zone_mapping.US" ),
189
+ resource .TestCheckResourceAttrSet (resourceName , "custom_zone_mapping.IE" ),
190
+ resource .TestCheckResourceAttrSet (resourceName , "custom_zone_mapping.DE" ),
191
+ resource .TestCheckResourceAttrSet (resourceName , "custom_zone_mapping.JP" ),
192
+ resource .TestCheckResourceAttr (resourceName , "cluster_name" , name ),
193
+ resource .TestCheckResourceAttr (resourceName , "project_id" , projectID ),
194
+ testAccCheckMongoDBAtlasGlobalClusterAttributes (& globalConfig , 5 ),
195
+ ),
196
+ },
197
+ {
198
+ ResourceName : resourceName ,
199
+ ImportStateIdFunc : testAccCheckMongoDBAtlasGlobalClusterImportStateIDFunc (resourceName ),
200
+ ImportState : true ,
201
+ ImportStateVerify : true ,
202
+ ImportStateVerifyIgnore : []string {"custom_zone_mappings" },
203
+ },
204
+ },
205
+ })
206
+ }
207
+
122
208
func testAccCheckMongoDBAtlasGlobalClusterExists (resourceName string , globalConfig * matlas.GlobalCluster ) resource.TestCheckFunc {
123
209
return func (s * terraform.State ) error {
124
210
conn := testAccProvider .Meta ().(* MongoDBClient ).Atlas
@@ -295,3 +381,104 @@ func testAccMongoDBAtlasGlobalClusterWithAWSClusterConfig(projectID, name, backu
295
381
}
296
382
` , projectID , name , backupEnabled )
297
383
}
384
+
385
+ func testAccMongoDBAtlasGlobalClusterWithDBConfig (projectID , name , backupEnabled , zones string ) string {
386
+ return fmt .Sprintf (`
387
+ resource "mongodbatlas_database_user" "test" {
388
+ username = "horizonv2-sg"
389
+ password = "password testing something"
390
+ project_id = %[1]q
391
+ auth_database_name = "admin"
392
+
393
+ roles {
394
+ role_name = "readWrite"
395
+ database_name = "horizonv2-sg"
396
+ }
397
+ }
398
+
399
+ resource "mongodbatlas_cluster" "test" {
400
+ project_id = %[1]q
401
+ name = %[2]q
402
+ disk_size_gb = 80
403
+ cloud_backup = %[3]s
404
+ cluster_type = "GEOSHARDED"
405
+
406
+ // Provider Settings "block"
407
+ provider_name = "AWS"
408
+ provider_instance_size_name = "M30"
409
+
410
+ replication_specs {
411
+ zone_name = "US"
412
+ num_shards = 1
413
+ regions_config {
414
+ region_name = "US_EAST_1"
415
+ electable_nodes = 3
416
+ priority = 7
417
+ read_only_nodes = 0
418
+ }
419
+ }
420
+ replication_specs {
421
+ zone_name = "EU"
422
+ num_shards = 1
423
+ regions_config {
424
+ region_name = "EU_WEST_1"
425
+ electable_nodes = 3
426
+ priority = 7
427
+ read_only_nodes = 0
428
+ }
429
+ }
430
+ replication_specs {
431
+ zone_name = "DE"
432
+ num_shards = 1
433
+ regions_config {
434
+ region_name = "EU_NORTH_1"
435
+ electable_nodes = 3
436
+ priority = 7
437
+ read_only_nodes = 0
438
+ }
439
+ }
440
+ replication_specs {
441
+ zone_name = "JP"
442
+ num_shards = 1
443
+ regions_config {
444
+ region_name = "AP_NORTHEAST_1"
445
+ electable_nodes = 3
446
+ priority = 7
447
+ read_only_nodes = 0
448
+ }
449
+ }
450
+ }
451
+
452
+ resource "mongodbatlas_global_cluster_config" "test" {
453
+ project_id = mongodbatlas_cluster.test.project_id
454
+ cluster_name = mongodbatlas_cluster.test.name
455
+
456
+ managed_namespaces {
457
+ db = "horizonv2-sg"
458
+ collection = "entitlements.entitlement"
459
+ custom_shard_key = "orgId"
460
+ }
461
+ managed_namespaces {
462
+ db = "horizonv2-sg"
463
+ collection = "entitlements.homesitemapping"
464
+ custom_shard_key = "orgId"
465
+ }
466
+ managed_namespaces {
467
+ db = "horizonv2-sg"
468
+ collection = "entitlements.site"
469
+ custom_shard_key = "orgId"
470
+ }
471
+ managed_namespaces {
472
+ db = "horizonv2-sg"
473
+ collection = "entitlements.userDesktopMapping"
474
+ custom_shard_key = "orgId"
475
+ }
476
+ managed_namespaces {
477
+ db = "horizonv2-sg"
478
+ collection = "session"
479
+ custom_shard_key = "orgId"
480
+ }
481
+ %s
482
+ }
483
+ ` , projectID , name , backupEnabled , zones )
484
+ }
0 commit comments