Skip to content

Commit e8c25fe

Browse files
authored
chore(Cloud Databases): Add tests and edit doc (IBM-Cloud#6302)
1 parent 0918584 commit e8c25fe

File tree

4 files changed

+262
-22
lines changed

4 files changed

+262
-22
lines changed

ibm/service/database/resource_ibm_database_mongodb_enterprise_test.go

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,6 @@ func TestAccIBMMongoDBEnterpriseDatabaseInstanceGroupBasic(t *testing.T) {
112112
resource.TestCheckResourceAttr(name, "groups.0.memory.0.allocation_mb", "49152"),
113113
resource.TestCheckResourceAttr(name, "groups.0.disk.0.allocation_mb", "61440"),
114114
resource.TestCheckResourceAttr(name, "groups.0.count", "3"),
115-
resource.TestCheckResourceAttr(name, "groups.1.count", "1"),
116-
resource.TestCheckResourceAttr(name, "groups.2.count", "1"),
117115
resource.TestCheckResourceAttr(name, "tags.#", "1"),
118116
),
119117
},
@@ -330,22 +328,6 @@ func testAccCheckIBMDatabaseInstanceMongoDBEnterpriseGroupBasic(databaseResource
330328
}
331329
}
332330
333-
group {
334-
group_id = "bi_connector"
335-
336-
members {
337-
allocation_count = 1
338-
}
339-
}
340-
341-
group {
342-
group_id = "analytics"
343-
344-
members {
345-
allocation_count = 1
346-
}
347-
}
348-
349331
timeouts {
350332
create = "4h"
351333
update = "4h"

ibm/service/database/resource_ibm_database_mongodb_sharding_test.go

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,46 @@ func TestAccIBMMongoDBShardingDatabaseInstanceBasic(t *testing.T) {
7373
})
7474
}
7575

76+
func TestAccIBMDatabaseInstanceMongoShardingHscale(t *testing.T) {
77+
t.Parallel()
78+
79+
databaseResourceGroup := "default"
80+
var databaseInstanceOne string
81+
rnd := fmt.Sprintf("tf-mongoSharding-%d", acctest.RandIntRange(10, 100))
82+
testName := rnd
83+
name := "ibm_database." + testName
84+
85+
resource.Test(t, resource.TestCase{
86+
PreCheck: func() { acc.TestAccPreCheck(t) },
87+
Providers: acc.TestAccProviders,
88+
CheckDestroy: testAccCheckIBMDatabaseInstanceDestroy,
89+
Steps: []resource.TestStep{
90+
{
91+
Config: testAccCheckIBMDatabaseInstanceMongoDBShardingMinimal(databaseResourceGroup, testName),
92+
Check: resource.ComposeAggregateTestCheckFunc(
93+
testAccCheckIBMDatabaseInstanceExists(name, &databaseInstanceOne),
94+
resource.TestCheckResourceAttr(name, "name", testName),
95+
resource.TestCheckResourceAttr(name, "service", "databases-for-mongodb"),
96+
resource.TestCheckResourceAttr(name, "plan", "enterprise-sharding"),
97+
resource.TestCheckResourceAttr(name, "location", acc.Region()),
98+
resource.TestCheckResourceAttr(name, "groups.0.count", "3"),
99+
),
100+
},
101+
{
102+
Config: testAccCheckIBMDatabaseInstanceMongoDBShardingHScale(databaseResourceGroup, testName),
103+
Check: resource.ComposeAggregateTestCheckFunc(
104+
testAccCheckIBMDatabaseInstanceExists(name, &databaseInstanceOne),
105+
resource.TestCheckResourceAttr(name, "name", testName),
106+
resource.TestCheckResourceAttr(name, "service", "databases-for-mongodb"),
107+
resource.TestCheckResourceAttr(name, "plan", "enterprise-sharding"),
108+
resource.TestCheckResourceAttr(name, "location", acc.Region()),
109+
resource.TestCheckResourceAttr(name, "groups.0.count", "6"),
110+
),
111+
},
112+
},
113+
})
114+
}
115+
76116
func testAccCheckIBMDatabaseInstanceMongoDBShardingBasic(databaseResourceGroup string, name string) string {
77117
return fmt.Sprintf(`
78118
data "ibm_resource_group" "test_acc" {
@@ -195,3 +235,72 @@ func testAccCheckIBMDatabaseInstanceMongoDBShardingReduced(databaseResourceGroup
195235
}
196236
`, databaseResourceGroup, name, acc.Region())
197237
}
238+
239+
func testAccCheckIBMDatabaseInstanceMongoDBShardingMinimal(databaseResourceGroup string, name string) string {
240+
return fmt.Sprintf(`
241+
data "ibm_resource_group" "test_acc" {
242+
name = "%[1]s"
243+
}
244+
245+
resource "ibm_database" "%[2]s" {
246+
resource_group_id = data.ibm_resource_group.test_acc.id
247+
name = "%[2]s"
248+
service = "databases-for-mongodb"
249+
plan = "enterprise-sharding"
250+
location = "%[3]s"
251+
service_endpoints = "private"
252+
253+
group {
254+
group_id = "member"
255+
256+
host_flavor {
257+
id = "b3c.4x16.encrypted"
258+
}
259+
260+
members {
261+
allocation_count = 3
262+
}
263+
}
264+
265+
timeouts {
266+
create = "480m"
267+
update = "480m"
268+
delete = "15m"
269+
}
270+
}
271+
`, databaseResourceGroup, name, acc.Region())
272+
}
273+
274+
func testAccCheckIBMDatabaseInstanceMongoDBShardingHScale(databaseResourceGroup string, name string) string {
275+
return fmt.Sprintf(`
276+
data "ibm_resource_group" "test_acc" {
277+
name = "%[1]s"
278+
}
279+
280+
resource "ibm_database" "%[2]s" {
281+
resource_group_id = data.ibm_resource_group.test_acc.id
282+
name = "%[2]s"
283+
service = "databases-for-mongodb"
284+
plan = "enterprise-sharding"
285+
location = "%[3]s"
286+
service_endpoints = "private"
287+
288+
group {
289+
group_id = "member"
290+
291+
host_flavor {
292+
id = "b3c.4x16.encrypted"
293+
}
294+
295+
members {
296+
allocation_count = 6
297+
}
298+
}
299+
timeouts {
300+
create = "480m"
301+
update = "480m"
302+
delete = "15m"
303+
}
304+
}
305+
`, databaseResourceGroup, name, acc.Region())
306+
}

ibm/service/database/validators_test.go

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,3 +364,149 @@ func TestValidateVersion(t *testing.T) {
364364
})
365365
}
366366
}
367+
368+
func TestValidateGroupScaling(t *testing.T) {
369+
tests := []struct {
370+
description string
371+
groupId string
372+
resourceName string
373+
value int
374+
resource *GroupResource
375+
nodeCount int
376+
expectedError string
377+
}{
378+
{
379+
description: "When group is NOT adjustable, Expect error",
380+
groupId: "member",
381+
resourceName: "members",
382+
value: 6,
383+
resource: &GroupResource{
384+
Units: "count",
385+
Allocation: 3,
386+
Minimum: 3,
387+
Maximum: 9,
388+
StepSize: 1,
389+
IsAdjustable: false,
390+
IsOptional: false,
391+
CanScaleDown: false,
392+
CPUEnforcementRatioCeilingMb: 0,
393+
CPUEnforcementRatioMb: 0,
394+
},
395+
nodeCount: 1,
396+
expectedError: "member can not change members value after create",
397+
},
398+
{
399+
description: "When new value is invalid step size, Expect error specifying increments",
400+
groupId: "member",
401+
resourceName: "members",
402+
value: 5,
403+
resource: &GroupResource{
404+
Units: "count",
405+
Allocation: 3,
406+
Minimum: 3,
407+
Maximum: 9,
408+
StepSize: 3,
409+
IsAdjustable: true,
410+
IsOptional: false,
411+
CanScaleDown: false,
412+
CPUEnforcementRatioCeilingMb: 0,
413+
CPUEnforcementRatioMb: 0,
414+
},
415+
nodeCount: 1,
416+
expectedError: "member group members must be >= 3 and <= 9 in increments of 3",
417+
},
418+
{
419+
description: "When new value is less than the min, Expect error specifying increments",
420+
groupId: "member",
421+
resourceName: "members",
422+
value: 2,
423+
resource: &GroupResource{
424+
Units: "count",
425+
Allocation: 3,
426+
Minimum: 3,
427+
Maximum: 9,
428+
StepSize: 1,
429+
IsAdjustable: true,
430+
IsOptional: false,
431+
CanScaleDown: false,
432+
CPUEnforcementRatioCeilingMb: 0,
433+
CPUEnforcementRatioMb: 0,
434+
},
435+
nodeCount: 1,
436+
expectedError: "member group members must be >= 3 and <= 9 in increments of 1",
437+
},
438+
{
439+
description: "When new value is more than the max, Expect error specifying increments",
440+
groupId: "member",
441+
resourceName: "members",
442+
value: 10,
443+
resource: &GroupResource{
444+
Units: "count",
445+
Allocation: 4,
446+
Minimum: 2,
447+
Maximum: 8,
448+
StepSize: 2,
449+
IsAdjustable: true,
450+
IsOptional: false,
451+
CanScaleDown: false,
452+
CPUEnforcementRatioCeilingMb: 0,
453+
CPUEnforcementRatioMb: 0,
454+
},
455+
nodeCount: 1,
456+
expectedError: "member group members must be >= 2 and <= 8 in increments of 2",
457+
},
458+
{
459+
description: "When new value is less than current value, Expect error cannot scale down increments",
460+
groupId: "member",
461+
resourceName: "members",
462+
value: 4,
463+
resource: &GroupResource{
464+
Units: "count",
465+
Allocation: 5,
466+
Minimum: 3,
467+
Maximum: 9,
468+
StepSize: 1,
469+
IsAdjustable: true,
470+
IsOptional: false,
471+
CanScaleDown: false,
472+
CPUEnforcementRatioCeilingMb: 0,
473+
CPUEnforcementRatioMb: 0,
474+
},
475+
nodeCount: 1,
476+
expectedError: "can not scale member group members below 5 to 4",
477+
},
478+
{
479+
description: "When new value is a valid increment, Expect no error",
480+
groupId: "member",
481+
resourceName: "members",
482+
value: 6,
483+
resource: &GroupResource{
484+
Units: "count",
485+
Allocation: 3,
486+
Minimum: 3,
487+
Maximum: 9,
488+
StepSize: 3,
489+
IsAdjustable: true,
490+
IsOptional: false,
491+
CanScaleDown: false,
492+
CPUEnforcementRatioCeilingMb: 0,
493+
CPUEnforcementRatioMb: 0,
494+
},
495+
nodeCount: 1,
496+
expectedError: "",
497+
},
498+
}
499+
500+
for _, tc := range tests {
501+
t.Run(tc.description, func(t *testing.T) {
502+
err := validateGroupScaling(tc.groupId, tc.resourceName, tc.value, tc.resource, tc.nodeCount)
503+
504+
if tc.expectedError != "" {
505+
require.Error(t, err)
506+
require.Contains(t, err.Error(), tc.expectedError)
507+
} else {
508+
require.NoError(t, err)
509+
}
510+
})
511+
}
512+
}

website/docs/r/database.html.markdown

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,9 @@ resource "ibm_database" "mongodb" {
285285

286286
### Sample MongoDB Enterprise database instance with BI Connector and Analytics
287287
* To enable Analytics and/or BI Connector for MongoDB Enterprise, a `group` attribute must be defined for the `analytics` and `bi_connector` group types with `members` scaled to at exactly `1`. Read more about Analytics and BI Connector [here](https://cloud.ibm.com/docs/databases-for-mongodb?topic=databases-for-mongodb-mongodbee-analytics)
288+
289+
> 🛑 **Deprectaed:** Analytics Add-On for Databases for MongoDB Enterprise Edition is deprecated after March 31,2025.
290+
288291
* MongoDB Enterprise provisioning may require more time than the default timeout. A longer timeout value can be set with using the `timeouts` attribute.
289292

290293
```terraform
@@ -688,13 +691,13 @@ Review the argument reference that you can specify for your resource.
688691
- `tags` (Optional, Array of Strings) A list of tags that you want to add to your instance.
689692
- `version` - (Optional, String) The version of the database to be provisioned or upgraded to. If omitted, the database is created with the latest supported major and minor version. This field can be updated to perform an in-place upgrade without forcing the creation of a new resource. The database will be put into READ-ONLY mode during upgrade. It is highly recommended to test before upgrading. To learn more, refer to the version upgrade documentation.
690693

691-
> ⚠️ **Warning:** Upgrading may require more time than the default timeout.
692-
> A longer timeout value can be set using the timeouts attribute.
694+
> ⚠️ **Warning:** Upgrading may require more time than the default timeout.
695+
> A longer timeout value can be set using the timeouts attribute.
693696
694697
- `version_upgrade_skip_backup` - (Optional, Boolean) Whether to skip taking a backup before upgrading the database version. This is only applicable to databases that do not support point-in-time restore (PITR). To learn more, refer to the version upgrade documentation.
695698

696-
> ⚠️ **Warning:** Skipping a backup is **not recommended**.
697-
> Skipping a backup before a version upgrade is dangerous and may result in **data loss** if the upgrade fails at any stage — there will be **no immediate backup** to restore from.
699+
> ⚠️ **Warning:** Skipping a backup is **not recommended**.
700+
> Skipping a backup before a version upgrade is dangerous and may result in **data loss** if the upgrade fails at any stage — there will be **no immediate backup** to restore from.
698701
699702
- `deletion_protection` - (Optional, Boolean) If the DB instance should have deletion protection within terraform enabled. This is not a property of the resource and does not prevent deletion outside of terraform. The database can't be deleted by terraform when this value is set to `true`. The default is `false`.
700703
- `users` - (Optional, List of Objects) A list of users that you want to create on the database. Multiple blocks are allowed.

0 commit comments

Comments
 (0)