Skip to content

Commit 2ada6d7

Browse files
authored
feat: added support for configuration in the module and the DA (#209)
1 parent f9c94fa commit 2ada6d7

File tree

9 files changed

+271
-15
lines changed

9 files changed

+271
-15
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ To attach access management tags to resources in this module, you need the follo
119119
| <a name="input_backup_crn"></a> [backup\_crn](#input\_backup\_crn) | The CRN of a backup resource to restore from. The backup is created by a database deployment with the same service ID. The backup is loaded after provisioning and the new deployment starts up that uses that data. A backup CRN is in the format crn:v1:<…>:backup:. If omitted, the database is provisioned empty. | `string` | `null` | no |
120120
| <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 |
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/> }))</pre> | `[]` | no |
122+
| <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 |
122123
| <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 |
123124
| <a name="input_member_cpu_count"></a> [member\_cpu\_count](#input\_member\_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 |
124125
| <a name="input_member_disk_mb"></a> [member\_disk\_mb](#input\_member\_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 |

main.tf

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -173,18 +173,20 @@ resource "time_sleep" "wait_for_backup_kms_authorization_policy" {
173173

174174
# Create MySQL database
175175
resource "ibm_database" "mysql_db" {
176-
depends_on = [time_sleep.wait_for_authorization_policy]
177-
resource_group_id = var.resource_group_id
178-
name = var.name
179-
service = "databases-for-mysql"
180-
location = var.region
181-
plan = "standard" # Only standard plan is available for mysql
182-
backup_id = var.backup_crn
183-
remote_leader_id = var.remote_leader_crn
184-
version = var.mysql_version
185-
tags = var.resource_tags
186-
adminpassword = var.admin_pass
187-
service_endpoints = var.service_endpoints
176+
depends_on = [time_sleep.wait_for_authorization_policy]
177+
resource_group_id = var.resource_group_id
178+
name = var.name
179+
service = "databases-for-mysql"
180+
location = var.region
181+
plan = "standard" # Only standard plan is available for mysql
182+
backup_id = var.backup_crn
183+
remote_leader_id = var.remote_leader_crn
184+
version = var.mysql_version
185+
tags = var.resource_tags
186+
adminpassword = var.admin_pass
187+
service_endpoints = var.service_endpoints
188+
# remove elements with null values: see https://github.com/terraform-ibm-modules/terraform-ibm-icd-postgresql/issues/273
189+
configuration = var.configuration != null ? jsonencode({ for k, v in var.configuration : k => v if v != null }) : null
188190
key_protect_key = var.kms_key_crn
189191
backup_encryption_key_crn = local.backup_encryption_key_crn
190192
point_in_time_recovery_deployment_id = var.pitr_id

modules/fscloud/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ No resources.
3636
| <a name="input_backup_crn"></a> [backup\_crn](#input\_backup\_crn) | The CRN of a backup resource to restore from. The backup is created by a database deployment with the same service ID. The backup is loaded after provisioning and the new deployment starts up that uses that data. A backup CRN is in the format crn:v1:<…>:backup:. If omitted, the database is provisioned empty. | `string` | `null` | no |
3737
| <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 |
3838
| <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/> }))</pre> | `[]` | no |
39+
| <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 |
3940
| <a name="input_instance_name"></a> [instance\_name](#input\_instance\_name) | The name to give the MySQL instance. | `string` | n/a | yes |
4041
| <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 |
4142
| <a name="input_member_cpu_count"></a> [member\_cpu\_count](#input\_member\_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` | `3` | no |

modules/fscloud/main.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module "mysql_db" {
33
resource_group_id = var.resource_group_id
44
name = var.instance_name
55
region = var.region
6+
remote_leader_crn = var.remote_leader_crn
67
skip_iam_authorization_policy = var.skip_iam_authorization_policy
78
service_endpoints = "private"
89
mysql_version = var.mysql_version
@@ -15,6 +16,7 @@ module "mysql_db" {
1516
resource_tags = var.resource_tags
1617
access_tags = var.access_tags
1718
cbr_rules = var.cbr_rules
19+
configuration = var.configuration
1820
member_memory_mb = var.member_memory_mb
1921
member_disk_mb = var.member_disk_mb
2022
member_cpu_count = var.member_cpu_count
@@ -24,5 +26,4 @@ module "mysql_db" {
2426
users = var.users
2527
service_credential_names = var.service_credential_names
2628
auto_scaling = var.auto_scaling
27-
remote_leader_crn = var.remote_leader_crn
2829
}

modules/fscloud/variables.tf

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,29 @@ variable "access_tags" {
101101
default = []
102102
}
103103

104+
variable "configuration" {
105+
type = object({
106+
default_authentication_plugin = optional(string) # sha256_password,caching_sha2_password,mysql_native_password
107+
innodb_buffer_pool_size_percentage = optional(number) # 10 ≤ value ≤ 100
108+
innodb_flush_log_at_trx_commit = optional(number) # 0 ≤ value ≤ 2
109+
innodb_log_buffer_size = optional(number) # 1048576 ≤ value ≤ 4294967295
110+
innodb_log_file_size = optional(number) # 4194304 ≤ value ≤ 274877906900
111+
innodb_lru_scan_depth = optional(number) # 128 ≤ value ≤ 2048
112+
innodb_read_io_threads = optional(number) # 1 ≤ value ≤ 64
113+
innodb_write_io_threads = optional(number) # 1 ≤ value ≤ 64
114+
max_allowed_packet = optional(number) # 1024 ≤ value ≤ 1073741824
115+
max_connections = optional(number) # 100 ≤ value ≤ 200000
116+
max_prepared_stmt_count = optional(number) # 0 ≤ value ≤ 4194304
117+
mysql_max_binlog_age_sec = optional(number) # 300 ≤ value ≤ 1073741823 Default: 1800
118+
net_read_timeout = optional(number) # 1 ≤ value ≤ 7200
119+
net_write_timeout = optional(number) # 1 ≤ value ≤ 7200
120+
sql_mode = optional(string) # The comma-separated list of SQL modes applied on this server globally.
121+
wait_timeout = optional(number) # 1 ≤ value ≤ 31536000
122+
})
123+
description = "Database configuration parameters, see https://cloud.ibm.com/docs/databases-for-mysql?topic=databases-for-mysql-changing-configuration&interface=api for more details."
124+
default = null
125+
}
126+
104127
##############################################################
105128
# Auto Scaling
106129
##############################################################

solutions/standard/DA-types.md

Lines changed: 88 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ The disk object in the `auto_scaling` input contains the following options. All
157157
- `rate_period_seconds`: How long (in seconds) the rate limit is applied for disk (default: `900` (15 minutes)).
158158
- `rate_units`: The units to use for the rate increase (default: `"mb"` (megabytes)).
159159

160-
161160
### Memory options for auto_scaling
162161

163162
The memory object within auto_scaling contains the following options. All options are optional.
@@ -198,3 +197,91 @@ The following example shows values for both disk and memory for the `auto_scalin
198197
}
199198
}
200199
```
200+
201+
## Configuration <a name="configuration"></a>
202+
203+
The Configuration variable tunes the MySQL database to suit different use case. For more information, see [Configuration](https://cloud.ibm.com/docs/databases-for-mysql?topic=databases-for-mysql-changing-configuration&interface=cli).
204+
205+
- Variable name: `configuration`
206+
- Type: An object with multiple attributes i.e. `default_authentication_plugin`, `innodb_buffer_pool_size_percentage`, `innodb_flush_log_at_trx_commit`, `innodb_log_buffer_size` , `innodb_log_file_size` , `innodb_lru_scan_depth`, `innodb_write_io_threads`, `max_allowed_packet`, `max_connections`, `max_prepared_stmt_count`, `mysql_max_binlog_age_sec`, `net_write_timeout`, `sql_mode` and `wait_timeout`
207+
208+
### Options for configuration
209+
210+
The configuration object in the input contains the following options
211+
212+
**Available Settings. [Learn more](https://cloud.ibm.com/docs/databases-for-mysql?topic=databases-for-mysql-changing-configuration&interface=cli#available-config-settings).**
213+
214+
- `default_authentication_plugin`: Allowable values are `sha256_password`, `caching_sha2_password` and `mysql_native_password`. Note: Unless strictly necessary, don't use `mysql_native_password`. (default: `sha256_password`).
215+
216+
- `innodb_buffer_pool_size_percentage`: The percentage of memory to use for innodb_buffer_pool_size. The default value of 50% is a conservative value and works for databases of any size. If your database requires more RAM, this value can be increased. Setting this value too high can exceed your database's memory limits, which can cause it to crash. (default: `50`).
217+
218+
- `innodb_flush_log_at_trx_commit`: Controls the balance between strict ACID compliance for commit operations and higher performance that is possible when commit-related I/O operations are rearranged and done in batches. You can achieve better performance by changing the default value but then you can lose transactions in a crash. (default: `2`).
219+
220+
- `innodb_log_buffer_size`: The size in bytes of the buffer that InnoDB uses to write to the log files on disk. (default: `33554432`).
221+
222+
- `innodb_log_file_size`: The size in bytes of each log file in a log group. Innodb_log_file_size and innodb_log_files_in_group have been superseded by innodb_redo_log_capacity. Setting innodb_log_file_size will also set innodb_redo_log_capacity. (default: `104857600`).
223+
224+
- `innodb_lru_scan_depth`: A parameter that influences the algorithms and heuristics for the flush operation for the InnoDB buffer pool. A setting smaller than the default is generally suitable for most workloads. A value that is much higher than necessary might impact performance. Consider increasing the value only if you have spare I/O capacity under a typical workload. (default: `256`).
225+
226+
- `innodb_write_io_threads`: The number of I/O threads for write operations in InnoDB. (default: `4`).
227+
228+
- `max_allowed_packet`: (default: `16777216`).
229+
230+
- `max_connections`: (default: `200`).
231+
232+
- `max_prepared_stmt_count`: Specifies the total number of prepared statements on the server. (default: `16382`).
233+
234+
- `mysql_max_binlog_age_sec`: (default: `1800`).
235+
236+
- `net_write_timeout`: The number of seconds to wait for a block to be written to a connection before aborting the write. (default: `60`).
237+
238+
- `sql_mode`: Allowable values:
239+
- ALLOW_INVALID_DATES
240+
- ANSI_QUOTES
241+
- ERROR_FOR_DIVISION_BY_ZERO
242+
- HIGH_NOT_PRECEDENCE
243+
- IGNORE_SPACE
244+
- NO_AUTO_CREATE_USER
245+
- NO_AUTO_VALUE_ON_ZERO
246+
- NO_BACKSLASH_ESCAPES
247+
- NO_DIR_IN_CREATE
248+
- NO_ENGINE_SUBSTITUTION
249+
- NO_FIELD_OPTIONS
250+
- NO_KEY_OPTIONS
251+
- NO_TABLE_OPTIONS
252+
- NO_UNSIGNED_SUBTRACTION
253+
- NO_ZERO_DATE
254+
- NO_ZERO_IN_DATE
255+
- ONLY_FULL_GROUP_BY
256+
- PAD_CHAR_TO_FULL_LENGTH
257+
- PIPES_AS_CONCAT
258+
- REAL_AS_FLOAT
259+
- STRICT_ALL_TABLES
260+
- STRICT_TRANS_TABLES
261+
262+
- `wait_timeout`: The number of seconds the server waits for activity on a noninteractive connection before closing it. (default: `28800`).
263+
264+
### Example configuration
265+
266+
The following example shows values for the `configuration` input.
267+
268+
```hcl
269+
{
270+
default_authentication_plugin = "sha256_password"
271+
innodb_buffer_pool_size_percentage = 50
272+
innodb_flush_log_at_trx_commit = 2
273+
innodb_log_buffer_size = 33554432
274+
innodb_log_file_size = 104857600
275+
innodb_lru_scan_depth = 256
276+
innodb_read_io_threads = 4
277+
innodb_write_io_threads = 4
278+
max_allowed_packet = 16777216
279+
max_connections = 200
280+
max_prepared_stmt_count = 16382
281+
mysql_max_binlog_age_sec = 1800
282+
net_read_timeout = 60
283+
net_write_timeout = 60
284+
sql_mode = "NO_ZERO_IN_DATE,NO_ENGINE_SUBSTITUTION"
285+
wait_timeout = 28800
286+
}
287+
```

0 commit comments

Comments
 (0)