Skip to content

Commit 716c24d

Browse files
authored
feat: support added for in-place version upgrade and deletion protection (#307) <br> - Supporting Terraform Deletion Protection with new input deletion_protection <br> - Allow for in-place major version upgrade (use new input version_upgrade_skip_backup to control backup in this scenario) <br> - **NOTE:** Database will be unavailable during upgrade, plan accordingly
* feat: major inplace upgrade, deletion protection * fix: remove reference to redis * fix: review comments
1 parent c45f363 commit 716c24d

30 files changed

+280
-134
lines changed

.secrets.baseline

Lines changed: 19 additions & 1 deletion
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-01-20T16:07:13Z",
6+
"generated_at": "2025-07-23T16:20:34Z",
77
"plugins_used": [
88
{
99
"name": "AWSKeyDetector"
@@ -86,6 +86,24 @@
8686
"type": "Secret Keyword",
8787
"verified_result": null
8888
}
89+
],
90+
"solutions/fully-configurable/DA-types.md": [
91+
{
92+
"hashed_secret": "44cdfc3615970ada14420caaaa5c5745fca06002",
93+
"is_secret": false,
94+
"is_verified": false,
95+
"line_number": 125,
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": 130,
104+
"type": "Secret Keyword",
105+
"verified_result": null
106+
}
89107
]
90108
},
91109
"version": "0.13.1+ibm.62.dss",

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ To attach access management tags to resources in this module, you need the follo
121121
| <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/> }))</pre> | `[]` | no |
122122
| <a name="input_configuration"></a> [configuration](#input\_configuration) | Database configuration parameters, see https://cloud.ibm.com/docs/databases-for-mysql?topic=databases-for-mysql-changing-configuration&interface=api for more details. | <pre>object({<br/> default_authentication_plugin = optional(string) # sha256_password,caching_sha2_password,mysql_native_password<br/> innodb_buffer_pool_size_percentage = optional(number) # 10 ≤ value ≤ 100<br/> innodb_flush_log_at_trx_commit = optional(number) # 0 ≤ value ≤ 2<br/> innodb_log_buffer_size = optional(number) # 1048576 ≤ value ≤ 4294967295<br/> innodb_log_file_size = optional(number) # 4194304 ≤ value ≤ 274877906900<br/> innodb_lru_scan_depth = optional(number) # 128 ≤ value ≤ 2048<br/> innodb_read_io_threads = optional(number) # 1 ≤ value ≤ 64<br/> innodb_write_io_threads = optional(number) # 1 ≤ value ≤ 64<br/> max_allowed_packet = optional(number) # 1024 ≤ value ≤ 1073741824<br/> max_connections = optional(number) # 100 ≤ value ≤ 200000<br/> max_prepared_stmt_count = optional(number) # 0 ≤ value ≤ 4194304<br/> mysql_max_binlog_age_sec = optional(number) # 300 ≤ value ≤ 1073741823 Default: 1800<br/> net_read_timeout = optional(number) # 1 ≤ value ≤ 7200<br/> net_write_timeout = optional(number) # 1 ≤ value ≤ 7200<br/> sql_mode = optional(string) # The comma-separated list of SQL modes applied on this server globally<br/> wait_timeout = optional(number) # 1 ≤ value ≤ 31536000<br/> })</pre> | `null` | no |
123123
| <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-mysql?topic=databases-for-mysql-resources-scaling) | `number` | `0` | no |
124+
| <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 |
124125
| <a name="input_disk_mb"></a> [disk\_mb](#input\_disk\_mb) | Allocated disk per member. [Learn more](https://cloud.ibm.com/docs/databases-for-mysql?topic=databases-for-mysql-resources-scaling) | `number` | `10240` | no |
125126
| <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 |
126127
| <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 |
@@ -137,10 +138,12 @@ To attach access management tags to resources in this module, you need the follo
137138
| <a name="input_service_endpoints"></a> [service\_endpoints](#input\_service\_endpoints) | Specify whether you want to enable the public, private, or both service endpoints. Supported values are 'public', 'private', or 'public-and-private'. | `string` | `"private"` | no |
138139
| <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 MySQL 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 |
139140
| <a name="input_tags"></a> [tags](#input\_tags) | Optional list of tags to be added to the MySQL instance. | `list(string)` | `[]` | no |
141+
| <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 |
140142
| <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 |
141143
| <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 |
142144
| <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 |
143145
| <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 MySQL instance. These blocks creates native MySQL database users, more info on that can be found here https://cloud.ibm.com/docs/databases-for-mysql?topic=databases-for-mysql-user-management | <pre>list(object({<br/> name = string<br/> password = string # pragma: allowlist secret<br/> type = optional(string)<br/> role = optional(string)<br/> }))</pre> | `[]` | no |
146+
| <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 |
144147

145148
### Outputs
146149

examples/backup/main.tf

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@ module "restored_mysql_db" {
1919
# remove the above line and uncomment the below 2 lines to consume the module from the registry
2020
# source = "terraform-ibm-modules/icd-mysql/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}-mysql-restored"
24-
mysql_version = var.mysql_version
25-
region = var.region
26-
tags = var.resource_tags
27-
access_tags = var.access_tags
28-
member_host_flavor = "multitenant"
29-
backup_crn = data.ibm_database_backups.backup_database.backups[0].backup_id
22+
resource_group_id = module.resource_group.resource_group_id
23+
name = "${var.prefix}-mysql-restored"
24+
mysql_version = var.mysql_version
25+
region = var.region
26+
tags = var.resource_tags
27+
access_tags = var.access_tags
28+
member_host_flavor = "multitenant"
29+
deletion_protection = false
30+
backup_crn = data.ibm_database_backups.backup_database.backups[0].backup_id
3031
}

examples/basic/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Basic with read-only replica example
22

3-
An end-to-end example that uses the module's default variable values. This example uses the IBM Cloud terraform provider to:
3+
An end-to-end example that creates the following infrastructure:
44

5-
- Create a new resource group if one is not passed in.
6-
- Create a new ICD MySQL database instance.
7-
- Create a read-only replica of the leader MySQL database instance. For more info on Read-only Replicas, see [Configuring Read-only Replicas](https://cloud.ibm.com/docs/databases-for-mysql?topic=databases-for-mysql-read-replicas)
5+
- A resource group, if one is not passed in.
6+
- An ICD MySQL database instance.
7+
- A read-only replica of the leader MySQL database instance. For more info on Read-only Replicas, see [Configuring Read-only Replicas](https://cloud.ibm.com/docs/databases-for-mysql?topic=databases-for-mysql-read-replicas)

examples/basic/main.tf

Lines changed: 20 additions & 18 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-mysql/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}-mysql"
24-
mysql_version = var.mysql_version
25-
region = var.region
26-
access_tags = var.access_tags
27-
service_endpoints = var.service_endpoints
28-
tags = var.resource_tags
29-
member_host_flavor = var.member_host_flavor
22+
resource_group_id = module.resource_group.resource_group_id
23+
name = "${var.prefix}-mysql"
24+
region = var.region
25+
mysql_version = var.mysql_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
"mysql_admin" : "Administrator",
3233
"mysql_operator" : "Operator",
@@ -59,14 +60,15 @@ module "read_only_replica_mysql_db" {
5960
# remove the above line and uncomment the below 2 lines to consume the module from the registry
6061
# source = "terraform-ibm-modules/icd-mysql/ibm"
6162
# version = "X.Y.Z" # Replace "X.Y.Z" with a release version to lock into a specific release
62-
resource_group_id = module.resource_group.resource_group_id
63-
name = "${var.prefix}-read-only-replica-${count.index}"
64-
region = var.region
65-
tags = var.resource_tags
66-
access_tags = var.access_tags
67-
mysql_version = var.mysql_version
68-
remote_leader_crn = module.database.crn
69-
memory_mb = 12288 # Must be an increment of 384 megabytes. The minimum size of a read-only replica is 12 GB RAM
70-
disk_mb = 10240 # Must be an increment of 512 megabytes. The minimum size of a read-only replica is 10 GB of disk
71-
depends_on = [time_sleep.wait_time]
63+
resource_group_id = module.resource_group.resource_group_id
64+
name = "${var.prefix}-read-only-replica-${count.index}"
65+
region = var.region
66+
tags = var.resource_tags
67+
access_tags = var.access_tags
68+
mysql_version = var.mysql_version
69+
deletion_protection = false
70+
remote_leader_crn = module.database.crn
71+
memory_mb = 12288 # Must be an increment of 384 megabytes. The minimum size of a read-only replica is 12 GB RAM
72+
disk_mb = 10240 # Must be an increment of 512 megabytes. The minimum size of a read-only replica is 10 GB of disk
73+
depends_on = [time_sleep.wait_time]
7274
}

examples/basic/outputs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Outputs
33
##############################################################################
44
output "id" {
5-
description = "MySQL instance id"
5+
description = "Database instance id"
66
value = module.database.id
77
}
88

examples/basic/variables.tf

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ variable "ibmcloud_api_key" {
66

77
variable "region" {
88
type = string
9-
description = "Region to provision all resources created by this example."
9+
description = "Region to provision all resources created by this example"
1010
default = "us-south"
1111
}
1212

@@ -16,27 +16,27 @@ variable "prefix" {
1616
default = "mysql"
1717
}
1818

19-
variable "mysql_version" {
20-
description = "Version of the mysql instance. If no value passed, the current ICD preferred version is used."
21-
type = string
22-
default = null
23-
}
24-
2519
variable "resource_group" {
2620
type = string
2721
description = "An existing resource group name to use for this example, if unset a new resource group will be created"
2822
default = null
2923
}
3024

31-
variable "resource_tags" {
25+
variable "access_tags" {
3226
type = list(string)
33-
description = "Optional list of tags to be added to created resources"
27+
description = "A list of access tags to apply to the MySQL instance created by the module, see https://cloud.ibm.com/docs/account?topic=account-access-tags-tutorial for more details"
3428
default = []
3529
}
3630

37-
variable "access_tags" {
31+
variable "mysql_version" {
32+
type = string
33+
description = "Version of the mysql instance. If no value passed, the current ICD preferred version is used."
34+
default = null
35+
}
36+
37+
variable "resource_tags" {
3838
type = list(string)
39-
description = "A list of access tags to apply to the MySQL instance created by the module, see https://cloud.ibm.com/docs/account?topic=account-access-tags-tutorial for more details"
39+
description = "Optional list of tags to be added to created resources"
4040
default = []
4141
}
4242

@@ -52,6 +52,7 @@ variable "read_only_replicas_count" {
5252
error_message = "There is a limit of five read-only replicas per leader"
5353
}
5454
}
55+
5556
variable "service_endpoints" {
5657
type = string
5758
description = "The type of endpoint of the database instance. Possible values: `public`, `private`, `public-and-private`."
@@ -62,6 +63,7 @@ variable "service_endpoints" {
6263
error_message = "Valid values for service_endpoints are 'public', 'public-and-private', and 'private'"
6364
}
6465
}
66+
6567
variable "member_host_flavor" {
6668
type = string
6769
description = "The host flavor per member. [Learn more](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/database#host_flavor)."

examples/complete/main.tf

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,15 @@ module "mysql_db" {
106106
# remove the above line and uncomment the below 2 lines to consume the module from the registry
107107
# source = "terraform-ibm-modules/icd-mysql/ibm"
108108
# version = "X.Y.Z" # Replace "X.Y.Z" with a release version to lock into a specific release
109-
resource_group_id = module.resource_group.resource_group_id
110-
name = "${var.prefix}-mysql"
111-
region = var.region
112-
mysql_version = var.mysql_version
113-
admin_pass = var.admin_pass
114-
users = var.users
109+
resource_group_id = module.resource_group.resource_group_id
110+
name = "${var.prefix}-mysql"
111+
region = var.region
112+
mysql_version = var.mysql_version
113+
admin_pass = var.admin_pass
114+
users = var.users
115+
access_tags = var.access_tags
116+
tags = var.resource_tags
117+
deletion_protection = false
115118
# Example of how to use different KMS keys for data and backups
116119
use_ibm_owned_encryption_key = false
117120
use_same_kms_key_for_backups = false
@@ -123,8 +126,7 @@ module "mysql_db" {
123126
"mysql_viewer" : "Viewer",
124127
"mysql_editor" : "Editor",
125128
}
126-
tags = var.resource_tags
127-
access_tags = var.access_tags
129+
128130
member_host_flavor = "multitenant"
129131
cbr_rules = [
130132
{

examples/complete/outputs.tf

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
##############################################################################
22
# Outputs
33
##############################################################################
4+
45
output "id" {
56
description = "MySQL instance id"
67
value = module.mysql_db.id
78
}
89

10+
output "version" {
11+
description = "MySQL instance version"
12+
value = module.mysql_db.version
13+
}
14+
915
output "guid" {
1016
description = "MySQL instance guid"
1117
value = module.mysql_db.guid
1218
}
1319

14-
output "version" {
15-
description = "MySQL instance version"
16-
value = module.mysql_db.version
20+
output "crn" {
21+
description = "MySQL instance crn"
22+
value = module.mysql_db.crn
1723
}
1824

1925
output "service_credentials_json" {
@@ -28,11 +34,6 @@ output "service_credentials_object" {
2834
sensitive = true
2935
}
3036

31-
output "cbr_rule_ids" {
32-
description = "CBR rule ids created to restrict MySQL"
33-
value = module.mysql_db.cbr_rule_ids
34-
}
35-
3637
output "hostname" {
3738
description = "MySQL instance hostname"
3839
value = module.mysql_db.hostname
@@ -42,3 +43,8 @@ output "port" {
4243
description = "MySQL instance port"
4344
value = module.mysql_db.port
4445
}
46+
47+
output "cbr_rule_ids" {
48+
description = "CBR rule ids created to restrict MySQL"
49+
value = module.mysql_db.cbr_rule_ids
50+
}

0 commit comments

Comments
 (0)