Skip to content

Commit bfc6074

Browse files
authored
feat: added new input variable member_host_flavor and updated default value of memory_mb to 4096.<br><br>Reference: [Cloud Database Hosting Models](https://cloud.ibm.com/docs/cloud-databases?topic=cloud-databases-hosting-models)<br><br>The [host model switching](https://cloud.ibm.com/docs/cloud-databases?topic=cloud-databases-hosting-models&interface=api#hosting-models-switching) section has details of the migrations that the service is rolling out. All instances will have to be switched and the [time line](https://cloud.ibm.com/docs/cloud-databases?topic=cloud-databases-hosting-models&interface=api#hosting-model-transition-timeline) for the migrations is outlined.<br><br>During the transition both existing and new models are supported.<br><br>Users of this module should consider the changes being implemented by the service. It is recommended that new deployments use the shared or isolated compute models to start, by specifying the member_host_flavor. It is recommended that existing deployments make updates to control the upgrade process by specifying shared or isolate compute configurations and the resource required to run the service, by adding the member_host_flavor. (#366)
1 parent 0985908 commit bfc6074

File tree

9 files changed

+91
-22
lines changed

9 files changed

+91
-22
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,9 @@ You need the following permissions to run this module.
9393
| <a name="input_instance_name"></a> [instance\_name](#input\_instance\_name) | The name to give the MongoDB instance. | `string` | n/a | yes |
9494
| <a name="input_kms_encryption_enabled"></a> [kms\_encryption\_enabled](#input\_kms\_encryption\_enabled) | Set this to true to control the encryption keys used to encrypt the data that you store in IBM Cloud® Databases. If set to false, the data is encrypted by using randomly generated keys. For more info on Key Protect integration, see https://cloud.ibm.com/docs/cloud-databases?topic=cloud-databases-key-protect. For more info on HPCS integration, see https://cloud.ibm.com/docs/cloud-databases?topic=cloud-databases-hpcs | `bool` | `false` | no |
9595
| <a name="input_kms_key_crn"></a> [kms\_key\_crn](#input\_kms\_key\_crn) | The root key CRN of a Key Management Services like Key Protect or Hyper Protect Crypto Services (HPCS) that you want to use for disk encryption. Only used if var.kms\_encryption\_enabled is set to true. | `string` | `null` | no |
96+
| <a name="input_member_host_flavor"></a> [member\_host\_flavor](#input\_member\_host\_flavor) | Allocated host flavor per member. [Learn more](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/database#host_flavor). | `string` | `null` | no |
9697
| <a name="input_members"></a> [members](#input\_members) | Allocated number of members | `number` | `3` | no |
97-
| <a name="input_memory_mb"></a> [memory\_mb](#input\_memory\_mb) | Allocated memory per member. For more information, see https://cloud.ibm.com/docs/databases-for-mongodb?topic=databases-for-mongodb-pricing#mongodb-scale-member | `number` | `1024` | no |
98+
| <a name="input_memory_mb"></a> [memory\_mb](#input\_memory\_mb) | Allocated memory per member. For more information, see https://cloud.ibm.com/docs/databases-for-mongodb?topic=databases-for-mongodb-pricing#mongodb-scale-member | `number` | `4096` | no |
9899
| <a name="input_mongodb_version"></a> [mongodb\_version](#input\_mongodb\_version) | The version of the MongoDB to provision. If no value passed, the current ICD preferred version is used. For our version policy, see https://cloud.ibm.com/docs/cloud-databases?topic=cloud-databases-versioning-policy for more details | `string` | `null` | no |
99100
| <a name="input_plan"></a> [plan](#input\_plan) | The name of the service plan that you choose for your MongoDB instance | `string` | `"standard"` | no |
100101
| <a name="input_region"></a> [region](#input\_region) | The region where you want to deploy your instance. | `string` | `"us-south"` | no |

examples/backup-restore/main.tf

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ data "ibm_database_backups" "backup_database" {
1616

1717
# New mongo db instance pointing to the backup instance
1818
module "restored_mongo_db" {
19-
source = "../.."
20-
resource_group_id = module.resource_group.resource_group_id
21-
instance_name = "${var.prefix}-mongodb-restored"
22-
region = var.region
23-
mongodb_version = var.mongodb_version
24-
access_tags = var.access_tags
25-
tags = var.resource_tags
26-
backup_crn = data.ibm_database_backups.backup_database.backups[0].backup_id
19+
source = "../.."
20+
resource_group_id = module.resource_group.resource_group_id
21+
instance_name = "${var.prefix}-mongodb-restored"
22+
region = var.region
23+
mongodb_version = var.mongodb_version
24+
access_tags = var.access_tags
25+
tags = var.resource_tags
26+
member_host_flavor = "multitenant"
27+
backup_crn = data.ibm_database_backups.backup_database.backups[0].backup_id
2728
}

examples/complete/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ module "mongodb" {
9494
access_tags = var.access_tags
9595
tags = var.resource_tags
9696
service_credential_names = var.service_credential_names
97+
member_host_flavor = "multitenant"
9798
cbr_rules = [
9899
{
99100
description = "${var.prefix}-mongodb access only from vpc"

examples/fscloud/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ module "mongodb" {
6565
mongodb_version = var.mongodb_version
6666
service_credential_names = var.service_credential_names
6767
auto_scaling = var.auto_scaling
68+
member_host_flavor = "b3c.4x16.encrypted"
6869
backup_encryption_key_crn = var.backup_encryption_key_crn
6970
backup_crn = var.backup_crn
7071
cbr_rules = [

main.tf

Lines changed: 62 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ locals {
2222
# Determine if auto scaling is enabled
2323
auto_scaling_enabled = var.auto_scaling == null ? [] : [1]
2424

25+
# Determine if host_flavor is used
26+
host_flavor_set = var.member_host_flavor != null ? true : false
27+
2528
# Determine what KMS service is being used for database encryption
2629
kms_service = var.kms_key_crn != null ? (
2730
can(regex(".*kms.*", var.kms_key_crn)) ? "kms" : (
@@ -73,22 +76,69 @@ resource "ibm_database" "mongodb" {
7376
}
7477
}
7578

76-
group {
77-
group_id = "member"
78-
memory {
79-
allocation_mb = var.memory_mb
80-
}
81-
disk {
82-
allocation_mb = var.disk_mb
79+
## This for_each block is NOT a loop to attach to multiple group blocks.
80+
## This is used to conditionally add one, OR, the other group block depending on var.local.host_flavor_set
81+
## This block is for if host_flavor IS set to specific pre-defined host sizes and not set to "multitenant"
82+
dynamic "group" {
83+
for_each = local.host_flavor_set && var.member_host_flavor != "multitenant" ? [1] : []
84+
content {
85+
group_id = "member" # Only member type is allowed for IBM Cloud Databases
86+
host_flavor {
87+
id = var.member_host_flavor
88+
}
89+
disk {
90+
allocation_mb = var.disk_mb
91+
}
92+
members {
93+
allocation_count = var.members
94+
}
8395
}
84-
cpu {
85-
allocation_count = var.cpu_count
96+
}
97+
98+
## This block is for if host_flavor IS set to "multitenant"
99+
dynamic "group" {
100+
for_each = local.host_flavor_set && var.member_host_flavor == "multitenant" ? [1] : []
101+
content {
102+
group_id = "member" # Only member type is allowed for IBM Cloud Databases
103+
host_flavor {
104+
id = var.member_host_flavor
105+
}
106+
disk {
107+
allocation_mb = var.disk_mb
108+
}
109+
memory {
110+
allocation_mb = var.memory_mb
111+
}
112+
cpu {
113+
allocation_count = var.cpu_count
114+
}
115+
members {
116+
allocation_count = var.members
117+
}
86118
}
87-
members {
88-
allocation_count = var.members
119+
}
120+
121+
## This block is for if host_flavor IS NOT set
122+
dynamic "group" {
123+
for_each = local.host_flavor_set ? [] : [1]
124+
content {
125+
group_id = "member" # Only member type is allowed for IBM Cloud Databases
126+
memory {
127+
allocation_mb = var.memory_mb
128+
}
129+
disk {
130+
allocation_mb = var.disk_mb
131+
}
132+
cpu {
133+
allocation_count = var.cpu_count
134+
}
135+
members {
136+
allocation_count = var.members
137+
}
89138
}
90139
}
91140

141+
92142
## This for_each block is NOT a loop to attach to multiple auto_scaling blocks.
93143
## This block is only used to conditionally add auto_scaling block depending on var.auto_scaling
94144
dynamic "auto_scaling" {
@@ -168,7 +218,7 @@ module "cbr_rule" {
168218
}
169219
]
170220
}]
171-
# There is only 1 operation type for Redis so it is not exposed as a configuration
221+
# There is only 1 operation type for MongoDB so it is not exposed as a configuration
172222
operations = [{
173223
api_types = [
174224
{

modules/fscloud/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ No resources.
4141
| <a name="input_existing_kms_instance_guid"></a> [existing\_kms\_instance\_guid](#input\_existing\_kms\_instance\_guid) | The GUID of the Hyper Protect Crypto Services instance. | `string` | n/a | yes |
4242
| <a name="input_instance_name"></a> [instance\_name](#input\_instance\_name) | Name of the mongodb instance | `string` | n/a | yes |
4343
| <a name="input_kms_key_crn"></a> [kms\_key\_crn](#input\_kms\_key\_crn) | The root key CRN of the Hyper Protect Crypto Service (HPCS) to use for disk encryption. | `string` | n/a | yes |
44+
| <a name="input_member_host_flavor"></a> [member\_host\_flavor](#input\_member\_host\_flavor) | Allocated host flavor per member. [Learn more](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/database#host_flavor). | `string` | `null` | no |
4445
| <a name="input_members"></a> [members](#input\_members) | Allocated number of members | `number` | `3` | no |
4546
| <a name="input_memory_mb"></a> [memory\_mb](#input\_memory\_mb) | Allocated memory per member. For more information, see https://cloud.ibm.com/docs/databases-for-mongodb?topic=databases-for-mongodb-pricing#mongodb-scale-member | `number` | `14336` | no |
4647
| <a name="input_mongodb_version"></a> [mongodb\_version](#input\_mongodb\_version) | Version of the MongoDB instance. If no value is passed, the current preferred version of IBM Cloud Databases is used. | `string` | `null` | no |

modules/fscloud/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ module "mongodb" {
2020
users = var.users
2121
disk_mb = var.disk_mb
2222
cpu_count = var.cpu_count
23+
member_host_flavor = var.member_host_flavor
2324
auto_scaling = var.auto_scaling
2425
service_credential_names = var.service_credential_names
2526
backup_crn = var.backup_crn

modules/fscloud/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ variable "cpu_count" {
5959
# Validation is done in terraform plan phase by IBM provider, so no need to add any extra validation here
6060
}
6161

62+
variable "member_host_flavor" {
63+
type = string
64+
description = "Allocated host flavor per member. [Learn more](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/database#host_flavor)."
65+
default = null
66+
}
67+
6268
variable "members" {
6369
type = number
6470
description = "Allocated number of members"

variables.tf

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ variable "endpoints" {
7878
variable "memory_mb" {
7979
type = number
8080
description = "Allocated memory per member. For more information, see https://cloud.ibm.com/docs/databases-for-mongodb?topic=databases-for-mongodb-pricing#mongodb-scale-member"
81-
default = 1024
81+
default = 4096
8282
# Validation is done in the Terraform plan phase by the IBM provider, so no need to add extra validation here.
8383
}
8484

@@ -96,6 +96,13 @@ variable "cpu_count" {
9696
# Validation is done in the Terraform plan phase by the IBM provider, so no need to add extra validation here.
9797
}
9898

99+
variable "member_host_flavor" {
100+
type = string
101+
description = "Allocated host flavor per member. [Learn more](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/database#host_flavor)."
102+
default = null
103+
# Validation is done in the Terraform plan phase by the IBM provider, so no need to add extra validation here.
104+
}
105+
99106
variable "members" {
100107
type = number
101108
description = "Allocated number of members"

0 commit comments

Comments
 (0)