Skip to content

Commit a4b9efa

Browse files
authored
feat: major in-place upgrade, deletion protection (#583)
1 parent 705a6e9 commit a4b9efa

File tree

21 files changed

+170
-105
lines changed

21 files changed

+170
-105
lines changed

.secrets.baseline

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"files": "go.sum|^.secrets.baseline$",
44
"lines": null
55
},
6-
"generated_at": "2024-06-27T12:07:30Z",
6+
"generated_at": "2025-07-17T12:16:53Z",
77
"plugins_used": [
88
{
99
"name": "AWSKeyDetector"
@@ -87,12 +87,20 @@
8787
"verified_result": null
8888
}
8989
],
90-
"module-metadata.json": [
90+
"solutions/fully-configurable/DA-types.md": [
9191
{
92-
"hashed_secret": "99075eb0baa8cfda1cae029da06b57b93cc13a31",
92+
"hashed_secret": "44cdfc3615970ada14420caaaa5c5745fca06002",
9393
"is_secret": false,
9494
"is_verified": false,
95-
"line_number": 407,
95+
"line_number": 124,
96+
"type": "Secret Keyword",
97+
"verified_result": null
98+
},
99+
{
100+
"hashed_secret": "bd0d0d73a240c29656fb8ae0dfa5f863077788dc",
101+
"is_secret": false,
102+
"is_verified": false,
103+
"line_number": 129,
96104
"type": "Secret Keyword",
97105
"verified_result": null
98106
}

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ You need the following permissions to run this module.
9191
| <a name="input_backup_encryption_key_crn"></a> [backup\_encryption\_key\_crn](#input\_backup\_encryption\_key\_crn) | The CRN of a Key Protect or Hyper Protect Crypto Services encryption key that you want to use for encrypting the disk that holds deployment backups. Applies only if `use_ibm_owned_encryption_key` is false and `use_same_kms_key_for_backups` is false. If no value is passed, and `use_same_kms_key_for_backups` is true, the value of `kms_key_crn` is used. Alternatively set `use_default_backup_encryption_key` to true to use the IBM Cloud Databases default encryption. Bare in mind that backups encryption is only available in certain regions. See [Bring your own key for backups](https://cloud.ibm.com/docs/cloud-databases?topic=cloud-databases-key-protect&interface=ui#key-byok) and [Using the HPCS Key for Backup encryption](https://cloud.ibm.com/docs/cloud-databases?topic=cloud-databases-hpcs#use-hpcs-backups). | `string` | `null` | no |
9292
| <a name="input_cbr_rules"></a> [cbr\_rules](#input\_cbr\_rules) | (Optional, list) List of CBR rules to create | <pre>list(object({<br/> description = string<br/> account_id = string<br/> rule_contexts = list(object({<br/> attributes = optional(list(object({<br/> name = string<br/> value = string<br/> }))) }))<br/> enforcement_mode = string<br/> tags = optional(list(object({<br/> name = string<br/> value = string<br/> })))<br/> operations = optional(list(object({<br/> api_types = list(object({<br/> api_type_id = string<br/> }))<br/> })))<br/> }))</pre> | `[]` | no |
9393
| <a name="input_cpu_count"></a> [cpu\_count](#input\_cpu\_count) | Allocated dedicated CPU per member. For shared CPU, set to 0. [Learn more](https://cloud.ibm.com/docs/databases-for-mongodb?topic=databases-for-mongodb-pricing#mongodb-scale-member) | `number` | `0` | no |
94+
| <a name="input_deletion_protection"></a> [deletion\_protection](#input\_deletion\_protection) | Enable deletion protection within terraform. This is not a property of the resource and does not prevent deletion outside of terraform. The database can not be deleted by terraform when this value is set to 'true'. In order to delete with terraform the value must be set to 'false' and a terraform apply performed before the destroy is performed. The default is 'true'. | `bool` | `true` | no |
9495
| <a name="input_disk_mb"></a> [disk\_mb](#input\_disk\_mb) | The disk that is allocated per member. [Learn more](https://cloud.ibm.com/docs/databases-for-mongodb?topic=databases-for-mongodb-pricing#mongodb-scale-member) | `number` | `10240` | no |
9596
| <a name="input_kms_key_crn"></a> [kms\_key\_crn](#input\_kms\_key\_crn) | The CRN of a Key Protect or Hyper Protect Crypto Services encryption key to encrypt your data. Applies only if `use_ibm_owned_encryption_key` is false. By default this key is used for both deployment data and backups, but this behaviour can be altered using the `use_same_kms_key_for_backups` and `backup_encryption_key_crn` inputs. Bare in mind that backups encryption is only available in certain regions. See [Bring your own key for backups](https://cloud.ibm.com/docs/cloud-databases?topic=cloud-databases-key-protect&interface=ui#key-byok) and [Using the HPCS Key for Backup encryption](https://cloud.ibm.com/docs/cloud-databases?topic=cloud-databases-hpcs#use-hpcs-backups). | `string` | `null` | no |
9697
| <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 |
@@ -105,10 +106,12 @@ You need the following permissions to run this module.
105106
| <a name="input_service_endpoints"></a> [service\_endpoints](#input\_service\_endpoints) | Specify whether you want to enable the public or private endpoints on the instance. Supported values are 'public' or 'private'. | `string` | `"private"` | no |
106107
| <a name="input_skip_iam_authorization_policy"></a> [skip\_iam\_authorization\_policy](#input\_skip\_iam\_authorization\_policy) | Set to true to skip the creation of IAM authorization policies that permits all Databases for MongoDB instances in the given resource group 'Reader' access to the Key Protect or Hyper Protect Crypto Services key that was provided in the `kms_key_crn` and `backup_encryption_key_crn` inputs. This policy is required in order to enable KMS encryption, so only skip creation if there is one already present in your account. No policy is created if `use_ibm_owned_encryption_key` is true. | `bool` | `false` | no |
107108
| <a name="input_tags"></a> [tags](#input\_tags) | Optional list of tags to be added to the MongoDB instance. | `list(string)` | `[]` | no |
109+
| <a name="input_timeouts_update"></a> [timeouts\_update](#input\_timeouts\_update) | A database update may require a longer timeout for the update to complete. The default is 120 minutes. Set this variable to change the `update` value in the `timeouts` block. [Learn more](https://developer.hashicorp.com/terraform/language/resources/syntax#operation-timeouts). | `string` | `"120m"` | no |
108110
| <a name="input_use_default_backup_encryption_key"></a> [use\_default\_backup\_encryption\_key](#input\_use\_default\_backup\_encryption\_key) | When `use_ibm_owned_encryption_key` is set to false, backups will be encrypted with either the key specified in `kms_key_crn`, or in `backup_encryption_key_crn` if a value is passed. If you do not want to use your own key for backups encryption, you can set this to `true` to use the IBM Cloud Databases default encryption for backups. Alternatively set `use_ibm_owned_encryption_key` to true to use the default encryption for both backups and deployment data. | `bool` | `false` | no |
109111
| <a name="input_use_ibm_owned_encryption_key"></a> [use\_ibm\_owned\_encryption\_key](#input\_use\_ibm\_owned\_encryption\_key) | IBM Cloud Databases will secure your deployment's data at rest automatically with an encryption key that IBM hold. Alternatively, you may select your own Key Management System instance and encryption key (Key Protect or Hyper Protect Crypto Services) by setting this to false. If setting to false, a value must be passed for the `kms_key_crn` input. | `bool` | `true` | no |
110112
| <a name="input_use_same_kms_key_for_backups"></a> [use\_same\_kms\_key\_for\_backups](#input\_use\_same\_kms\_key\_for\_backups) | Set this to false if you wan't to use a different key that you own to encrypt backups. When set to false, a value is required for the `backup_encryption_key_crn` input. Alternatiely set `use_default_backup_encryption_key` to true to use the IBM Cloud Databases default encryption. Applies only if `use_ibm_owned_encryption_key` is false. Bare in mind that backups encryption is only available in certain regions. See [Bring your own key for backups](https://cloud.ibm.com/docs/cloud-databases?topic=cloud-databases-key-protect&interface=ui#key-byok) and [Using the HPCS Key for Backup encryption](https://cloud.ibm.com/docs/cloud-databases?topic=cloud-databases-hpcs#use-hpcs-backups). | `bool` | `true` | no |
111113
| <a name="input_users"></a> [users](#input\_users) | A list of users that you want to create on the database. Multiple blocks are allowed. The user password must be in the range of 10-32 characters. Be warned that in most case using IAM service credentials (via the var.service\_credential\_names) is sufficient to control access to the MongoDB instance. This blocks creates native MongoDB database users, more info on that can be found here https://cloud.ibm.com/docs/databases-for-mongodb?topic=databases-for-mongodb-user-management&interface=ui | <pre>list(object({<br/> name = string<br/> password = string # pragma: allowlist secret<br/> type = optional(string)<br/> role = optional(string)<br/> }))</pre> | `[]` | no |
114+
| <a name="input_version_upgrade_skip_backup"></a> [version\_upgrade\_skip\_backup](#input\_version\_upgrade\_skip\_backup) | Whether to skip taking a backup before upgrading the database version. Attention: Skipping a backup is not recommended. 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. | `bool` | `false` | no |
112115

113116
### Outputs
114117

examples/backup-restore/catalogValidationValues.json.template

Lines changed: 0 additions & 6 deletions
This file was deleted.

examples/backup-restore/main.tf

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ module "restored_icd_mongodb" {
2020
# remove the above line and uncomment the below 2 lines to consume the module from the registry
2121
# source = "terraform-ibm-modules/icd-mongodb/ibm/"
2222
# version = "X.Y.Z" # Replace "X.Y.Z" with a release version to lock into a specific release
23-
resource_group_id = module.resource_group.resource_group_id
24-
name = "${var.prefix}-mongodb-restored"
25-
region = var.region
26-
mongodb_version = var.mongodb_version
27-
access_tags = var.access_tags
28-
tags = var.resource_tags
29-
member_host_flavor = "multitenant"
30-
backup_crn = data.ibm_database_backups.backup_database.backups[0].backup_id
23+
resource_group_id = module.resource_group.resource_group_id
24+
name = "${var.prefix}-mongodb-restored"
25+
region = var.region
26+
mongodb_version = var.mongodb_version
27+
access_tags = var.access_tags
28+
tags = var.resource_tags
29+
member_host_flavor = "multitenant"
30+
deletion_protection = false
31+
backup_crn = data.ibm_database_backups.backup_database.backups[0].backup_id
3132
}

examples/basic/main.tf

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@ module "database" {
1919
# remove the above line and uncomment the below 2 lines to consume the module from the registry
2020
# source = "terraform-ibm-modules/icd-mongodb/ibm"
2121
# version = "X.Y.Z" # Replace "X.Y.Z" with a release version to lock into a specific release
22-
resource_group_id = module.resource_group.resource_group_id
23-
name = "${var.prefix}-data-store"
24-
region = var.region
25-
mongodb_version = var.mongodb_version
26-
access_tags = var.access_tags
27-
tags = var.resource_tags
28-
service_endpoints = var.service_endpoints
29-
member_host_flavor = var.member_host_flavor
22+
resource_group_id = module.resource_group.resource_group_id
23+
name = "${var.prefix}-data-store"
24+
region = var.region
25+
mongodb_version = var.mongodb_version
26+
access_tags = var.access_tags
27+
tags = var.resource_tags
28+
service_endpoints = var.service_endpoints
29+
member_host_flavor = var.member_host_flavor
30+
deletion_protection = false
3031
service_credential_names = {
3132
"mongodb_admin" : "Administrator",
3233
"mongodb_operator" : "Operator",

examples/complete/main.tf

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,16 +108,17 @@ module "icd_mongodb" {
108108
# remove the above line and uncomment the below 2 lines to consume the module from the registry
109109
# source = "terraform-ibm-modules/icd-mongodb/ibm"
110110
# version = "X.Y.Z" # Replace "X.Y.Z" with a release version to lock into a specific release
111-
resource_group_id = module.resource_group.resource_group_id
112-
name = "${var.prefix}-mongodb"
113-
mongodb_version = var.mongodb_version
114-
admin_pass = var.admin_pass
115-
users = var.users
116-
region = var.region
117-
plan = var.plan
118-
access_tags = var.access_tags
119-
tags = var.resource_tags
120-
auto_scaling = var.auto_scaling
111+
resource_group_id = module.resource_group.resource_group_id
112+
name = "${var.prefix}-mongodb"
113+
mongodb_version = var.mongodb_version
114+
admin_pass = var.admin_pass
115+
users = var.users
116+
region = var.region
117+
plan = var.plan
118+
access_tags = var.access_tags
119+
tags = var.resource_tags
120+
deletion_protection = false
121+
auto_scaling = var.auto_scaling
121122
# Example of how to use different KMS keys for data and backups
122123
use_ibm_owned_encryption_key = false
123124
use_same_kms_key_for_backups = false

examples/fscloud/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ module "mongodb" {
6363
region = var.region
6464
tags = var.resource_tags
6565
access_tags = var.access_tags
66+
deletion_protection = false
6667
kms_key_crn = var.kms_key_crn
6768
backup_encryption_key_crn = var.backup_encryption_key_crn
6869
backup_crn = var.backup_crn

ibm_catalog.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,15 @@
274274
}
275275
]
276276
},
277+
{
278+
"key": "deletion_protection"
279+
},
280+
{
281+
"key": "timeouts_update"
282+
},
283+
{
284+
"key": "version_upgrade_skip_backup"
285+
},
277286
{
278287
"key": "service_credential_names"
279288
},
@@ -571,6 +580,12 @@
571580
{
572581
"key": "auto_scaling"
573582
},
583+
{
584+
"key": "deletion_protection"
585+
},
586+
{
587+
"key": "timeouts_update"
588+
},
574589
{
575590
"key": "service_credential_names"
576591
},

main.tf

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -158,19 +158,21 @@ resource "time_sleep" "wait_for_backup_kms_authorization_policy" {
158158
########################################################################################################################
159159

160160
resource "ibm_database" "mongodb" {
161-
depends_on = [time_sleep.wait_for_authorization_policy, time_sleep.wait_for_backup_kms_authorization_policy]
162-
name = var.name
163-
plan = var.plan
164-
location = var.region
165-
service = "databases-for-mongodb"
166-
version = var.mongodb_version
167-
resource_group_id = var.resource_group_id
168-
service_endpoints = var.service_endpoints
169-
tags = var.tags
170-
adminpassword = var.admin_pass
171-
key_protect_key = var.kms_key_crn
172-
backup_encryption_key_crn = local.backup_encryption_key_crn
173-
backup_id = var.backup_crn
161+
depends_on = [time_sleep.wait_for_authorization_policy, time_sleep.wait_for_backup_kms_authorization_policy]
162+
name = var.name
163+
plan = var.plan
164+
location = var.region
165+
service = "databases-for-mongodb"
166+
version = var.mongodb_version
167+
resource_group_id = var.resource_group_id
168+
service_endpoints = var.service_endpoints
169+
deletion_protection = var.deletion_protection
170+
version_upgrade_skip_backup = var.version_upgrade_skip_backup
171+
tags = var.tags
172+
adminpassword = var.admin_pass
173+
key_protect_key = var.kms_key_crn
174+
backup_encryption_key_crn = local.backup_encryption_key_crn
175+
backup_id = var.backup_crn
174176

175177
dynamic "users" {
176178
for_each = nonsensitive(var.users != null ? var.users : [])
@@ -275,15 +277,14 @@ resource "ibm_database" "mongodb" {
275277
lifecycle {
276278
ignore_changes = [
277279
# Ignore changes to these because a change will destroy and recreate the instance
278-
version,
279280
key_protect_key,
280281
backup_encryption_key_crn,
281282
]
282283
}
283284

284285
timeouts {
285286
create = "120m" # Extending provisioning time to 120 minutes
286-
update = "120m"
287+
update = var.timeouts_update
287288
delete = "15m"
288289
}
289290
}

0 commit comments

Comments
 (0)