Skip to content

Commit 03029e3

Browse files
authored
feat: If host_flavor is set to multitenant, this will place the database on a logically separated, multi-tenant machine with minimum resource configurations required for multitenant config. (#405)
1 parent aeeaae9 commit 03029e3

File tree

4 files changed

+56
-2
lines changed

4 files changed

+56
-2
lines changed

examples/basic/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ module "postgresql_db" {
2323
resource_tags = var.resource_tags
2424
access_tags = var.access_tags
2525
member_host_flavor = var.member_host_flavor
26+
member_memory_mb = var.member_memory_mb
2627
}
2728

2829
# On destroy, we are seeing that even though the replica has been returned as

examples/basic/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,9 @@ variable "member_host_flavor" {
5656
description = "Allocated host flavor per member. For more information, see https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/database#host_flavor"
5757
default = null
5858
}
59+
60+
variable "member_memory_mb" {
61+
type = number
62+
description = "Allocated memory per-member. See the following doc for supported values: https://cloud.ibm.com/docs/databases-for-postgresql?topic=databases-for-postgresql-resources-scaling"
63+
default = 1024
64+
}

main.tf

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ resource "ibm_database" "postgresql_db" {
8484

8585
## This for_each block is NOT a loop to attach to multiple group blocks.
8686
## This is used to conditionally add one, OR, the other group block depending on var.local.host_flavor_set
87-
## This block is for if host_flavor IS set
87+
## This block is for if host_flavor IS set to specific pre-defined host sizes and not set to "multitenant"
8888
dynamic "group" {
89-
for_each = local.host_flavor_set ? [1] : []
89+
for_each = local.host_flavor_set && var.member_host_flavor != "multitenant" ? [1] : []
9090
content {
9191
group_id = "member" # Only member type is allowed for postgresql
9292
host_flavor {
@@ -104,6 +104,32 @@ resource "ibm_database" "postgresql_db" {
104104
}
105105
}
106106

107+
## This block is for if host_flavor IS set to "multitenant"
108+
dynamic "group" {
109+
for_each = local.host_flavor_set && var.member_host_flavor == "multitenant" ? [1] : []
110+
content {
111+
group_id = "member" # Only member type is allowed for postgresql
112+
host_flavor {
113+
id = var.member_host_flavor
114+
}
115+
disk {
116+
allocation_mb = var.member_disk_mb
117+
}
118+
memory {
119+
allocation_mb = var.member_memory_mb
120+
}
121+
cpu {
122+
allocation_count = var.member_cpu_count
123+
}
124+
dynamic "members" {
125+
for_each = var.remote_leader_crn == null ? [1] : []
126+
content {
127+
allocation_count = var.members
128+
}
129+
}
130+
}
131+
}
132+
107133
## This block is for if host_flavor IS NOT set
108134
dynamic "group" {
109135
for_each = local.host_flavor_set ? [] : [1]

tests/other_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,24 @@ func TestRunCompleteExample(t *testing.T) {
116116
assert.Nil(t, err, "This should not have errored")
117117
assert.NotNil(t, output, "Expected some output")
118118
}
119+
120+
func TestRunBasicExampleWithFlavorMultitenant(t *testing.T) {
121+
t.Parallel()
122+
123+
options := testhelper.TestOptionsDefaultWithVars(&testhelper.TestOptions{
124+
Testing: t,
125+
TerraformDir: "examples/basic",
126+
Prefix: "pg-flvr-multitenant",
127+
BestRegionYAMLPath: regionSelectionPath,
128+
ResourceGroup: resourceGroup,
129+
TerraformVars: map[string]interface{}{
130+
"member_host_flavor": "multitenant",
131+
"member_memory_mb": 8192, // Requires a minimum of 8192 megabytes with multitenant flavor
132+
},
133+
CloudInfoService: sharedInfoSvc,
134+
})
135+
136+
output, err := options.RunTestConsistency()
137+
assert.Nil(t, err, "This should not have errored")
138+
assert.NotNil(t, output, "Expected some output")
139+
}

0 commit comments

Comments
 (0)