Skip to content

Commit 5296138

Browse files
feat: Module updates (#220)
1 parent e591ca2 commit 5296138

File tree

25 files changed

+386
-220
lines changed

25 files changed

+386
-220
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,25 +118,25 @@ To attach access management tags to resources in this module, you need the follo
118118
| <a name="input_auto_scaling"></a> [auto\_scaling](#input\_auto\_scaling) | Optional rules to allow the database to increase resources in response to usage. Only a single autoscaling block is allowed. Make sure you understand the effects of autoscaling, especially for production environments. See https://ibm.biz/autoscaling-considerations in the IBM Cloud Docs. | <pre>object({<br/> disk = object({<br/> capacity_enabled = optional(bool, false)<br/> free_space_less_than_percent = optional(number, 10)<br/> io_above_percent = optional(number, 90)<br/> io_enabled = optional(bool, false)<br/> io_over_period = optional(string, "15m")<br/> rate_increase_percent = optional(number, 10)<br/> rate_limit_mb_per_member = optional(number, 3670016)<br/> rate_period_seconds = optional(number, 900)<br/> rate_units = optional(string, "mb")<br/> })<br/> memory = object({<br/> io_above_percent = optional(number, 90)<br/> io_enabled = optional(bool, false)<br/> io_over_period = optional(string, "15m")<br/> rate_increase_percent = optional(number, 10)<br/> rate_limit_mb_per_member = optional(number, 114688)<br/> rate_period_seconds = optional(number, 900)<br/> rate_units = optional(string, "mb")<br/> })<br/> })</pre> | `null` | no |
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 |
121-
| <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 |
121+
| <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 |
123+
| <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_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 |
123125
| <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 |
124-
| <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 |
125-
| <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 |
126126
| <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 |
127-
| <a name="input_member_memory_mb"></a> [member\_memory\_mb](#input\_member\_memory\_mb) | Allocated memory per-member. [Learn more](https://cloud.ibm.com/docs/databases-for-mysql?topic=databases-for-mysql-resources-scaling) | `number` | `4096` | no |
128127
| <a name="input_members"></a> [members](#input\_members) | Allocated number of members. Members can be scaled up but not down. | `number` | `3` | no |
128+
| <a name="input_memory_mb"></a> [memory\_mb](#input\_memory\_mb) | Allocated memory per-member. [Learn more](https://cloud.ibm.com/docs/databases-for-mysql?topic=databases-for-mysql-resources-scaling) | `number` | `4096` | no |
129129
| <a name="input_mysql_version"></a> [mysql\_version](#input\_mysql\_version) | Version of the MySQL instance to provision. If no value is passed, the current preferred version of IBM Cloud Databases is used. | `string` | `null` | no |
130130
| <a name="input_name"></a> [name](#input\_name) | The name given to the MySQL instance. | `string` | n/a | yes |
131131
| <a name="input_pitr_id"></a> [pitr\_id](#input\_pitr\_id) | (Optional) The ID of the source deployment MySQL instance that you want to recover back to. The MySQL instance is expected to be in an up and in running state. | `string` | `null` | no |
132132
| <a name="input_pitr_time"></a> [pitr\_time](#input\_pitr\_time) | (Optional) The timestamp in UTC format (%Y-%m-%dT%H:%M:%SZ) for any time in the last 7 days that you want to restore to. To retrieve the timestamp, run the command (ibmcloud cdb mysql earliest-pitr-timestamp <deployment name or CRN>). For more info on Point-in-time Recovery, see https://cloud.ibm.com/docs/databases-for-mysql?topic=databases-for-mysql-pitr | `string` | `null` | no |
133133
| <a name="input_region"></a> [region](#input\_region) | The region where you want to deploy your instance. | `string` | `"us-south"` | no |
134134
| <a name="input_remote_leader_crn"></a> [remote\_leader\_crn](#input\_remote\_leader\_crn) | A CRN of the leader database to make the replica(read-only) deployment. The leader database is created by a database deployment with the same service ID. A read-only replica is set up to replicate all of your data from the leader deployment to the replica deployment by using asynchronous replication. For more information, see https://cloud.ibm.com/docs/databases-for-mysql?topic=databases-for-mysql-read-replicas | `string` | `null` | no |
135135
| <a name="input_resource_group_id"></a> [resource\_group\_id](#input\_resource\_group\_id) | The resource group ID where the MySQL instance will be created. | `string` | n/a | yes |
136-
| <a name="input_resource_tags"></a> [resource\_tags](#input\_resource\_tags) | Optional list of tags to be added to the MySQL instance. | `list(string)` | `[]` | no |
137136
| <a name="input_service_credential_names"></a> [service\_credential\_names](#input\_service\_credential\_names) | Map of name, role for service credentials that you want to create for the database | `map(string)` | `{}` | no |
138137
| <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 |
139138
| <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 an IAM authorization policy that permits all MySQL database instances in the resource group to read the encryption key from the KMS instance. If set to false, pass in a value for the KMS instance in the existing\_kms\_instance\_guid variable. In addition, no policy is created if var.kms\_encryption\_enabled is set to false. | `bool` | `false` | no |
139+
| <a name="input_tags"></a> [tags](#input\_tags) | Optional list of tags to be added to the MySQL instance. | `list(string)` | `[]` | no |
140140
| <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 |
141141
| <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 |
142142
| <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 |

examples/backup/main.tf

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,8 @@ module "resource_group" {
99
resource_group_name = var.resource_group == null ? "${var.prefix}-resource-group" : null
1010
existing_resource_group_name = var.resource_group
1111
}
12-
13-
module "mysql_db" {
14-
count = var.mysql_db_backup_crn != null ? 0 : 1
15-
source = "../.."
16-
resource_group_id = module.resource_group.resource_group_id
17-
name = "${var.prefix}-mysql"
18-
mysql_version = var.mysql_version
19-
region = var.region
20-
resource_tags = var.resource_tags
21-
access_tags = var.access_tags
22-
member_host_flavor = "multitenant"
23-
}
24-
2512
data "ibm_database_backups" "backup_database" {
26-
count = var.mysql_db_backup_crn != null ? 0 : 1
27-
deployment_id = module.mysql_db[0].id
13+
deployment_id = var.existing_database_crn
2814
}
2915

3016
# New mysql instance pointing to the backup instance
@@ -34,8 +20,8 @@ module "restored_mysql_db" {
3420
name = "${var.prefix}-mysql-restored"
3521
mysql_version = var.mysql_version
3622
region = var.region
37-
resource_tags = var.resource_tags
23+
tags = var.resource_tags
3824
access_tags = var.access_tags
3925
member_host_flavor = "multitenant"
40-
backup_crn = var.mysql_db_backup_crn == null ? data.ibm_database_backups.backup_database[0].backups[0].backup_id : var.mysql_db_backup_crn
26+
backup_crn = data.ibm_database_backups.backup_database.backups[0].backup_id
4127
}

examples/backup/outputs.tf

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
##############################################################################
22
# Outputs
33
##############################################################################
4-
output "id" {
5-
description = "MySQL instance id"
6-
value = var.mysql_db_backup_crn == null ? module.mysql_db[0].id : null
7-
}
8-
94
output "restored_mysql_db_id" {
105
description = "Restored MySQL instance id"
116
value = module.restored_mysql_db.id

examples/backup/variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ variable "access_tags" {
4040
default = []
4141
}
4242

43-
variable "mysql_db_backup_crn" {
43+
variable "existing_database_crn" {
4444
type = string
4545
description = "The existing CRN of a backup resource to restore from. If null then it will create a new instance first and then create another instance pointing to the backup of the first instance."
4646
default = null

examples/basic/main.tf

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,22 @@ module "resource_group" {
1414
# ICD mysql database
1515
##############################################################################
1616

17-
module "mysql_db" {
18-
source = "../.."
19-
resource_group_id = module.resource_group.resource_group_id
20-
name = "${var.prefix}-mysql"
21-
mysql_version = var.mysql_version
22-
region = var.region
23-
resource_tags = var.resource_tags
24-
access_tags = var.access_tags
17+
module "database" {
18+
source = "../.."
19+
resource_group_id = module.resource_group.resource_group_id
20+
name = "${var.prefix}-mysql"
21+
mysql_version = var.mysql_version
22+
region = var.region
23+
access_tags = var.access_tags
24+
service_endpoints = var.service_endpoints
25+
tags = var.resource_tags
26+
member_host_flavor = var.member_host_flavor
27+
service_credential_names = {
28+
"mysql_admin" : "Administrator",
29+
"mysql_operator" : "Operator",
30+
"mysql_viewer" : "Viewer",
31+
"mysql_editor" : "Editor",
32+
}
2533
}
2634

2735
# On destroy, we are seeing that even though the replica has been returned as
@@ -33,7 +41,7 @@ module "mysql_db" {
3341
# adding a time sleep here.
3442

3543
resource "time_sleep" "wait_time" {
36-
depends_on = [module.mysql_db]
44+
depends_on = [module.database]
3745

3846
destroy_duration = "5m"
3947
}
@@ -48,11 +56,11 @@ module "read_only_replica_mysql_db" {
4856
resource_group_id = module.resource_group.resource_group_id
4957
name = "${var.prefix}-read-only-replica-${count.index}"
5058
region = var.region
51-
resource_tags = var.resource_tags
59+
tags = var.resource_tags
5260
access_tags = var.access_tags
5361
mysql_version = var.mysql_version
54-
remote_leader_crn = module.mysql_db.crn
55-
member_memory_mb = 12288 # Must be an increment of 384 megabytes. The minimum size of a read-only replica is 12 GB RAM
56-
member_disk_mb = 10240 # Must be an increment of 512 megabytes. The minimum size of a read-only replica is 10 GB of disk
62+
remote_leader_crn = module.database.crn
63+
memory_mb = 12288 # Must be an increment of 384 megabytes. The minimum size of a read-only replica is 12 GB RAM
64+
disk_mb = 10240 # Must be an increment of 512 megabytes. The minimum size of a read-only replica is 10 GB of disk
5765
depends_on = [time_sleep.wait_time]
5866
}

examples/basic/outputs.tf

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,36 @@
33
##############################################################################
44
output "id" {
55
description = "MySQL instance id"
6-
value = module.mysql_db.id
6+
value = module.database.id
7+
}
8+
9+
output "mysql_crn" {
10+
description = "Mysql CRN"
11+
value = module.database.crn
712
}
813

914
output "version" {
1015
description = "MySQL instance version"
11-
value = module.mysql_db.version
16+
value = module.database.version
1217
}
1318

1419
output "adminuser" {
1520
description = "Database admin user name"
16-
value = module.mysql_db.adminuser
21+
value = module.database.adminuser
1722
}
1823

1924
output "hostname" {
2025
description = "Database connection hostname"
21-
value = module.mysql_db.hostname
26+
value = module.database.hostname
2227
}
2328

2429
output "port" {
2530
description = "Database connection port"
26-
value = module.mysql_db.port
31+
value = module.database.port
2732
}
2833

2934
output "certificate_base64" {
3035
description = "Database connection certificate"
31-
value = module.mysql_db.certificate_base64
36+
value = module.database.certificate_base64
3237
sensitive = true
3338
}

examples/basic/variables.tf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,19 @@ variable "read_only_replicas_count" {
5252
error_message = "There is a limit of five read-only replicas per leader"
5353
}
5454
}
55+
variable "service_endpoints" {
56+
type = string
57+
description = "The type of endpoint of the database instance. Possible values: `public`, `private`, `public-and-private`."
58+
default = "public"
59+
60+
validation {
61+
condition = can(regex("public|public-and-private|private", var.service_endpoints))
62+
error_message = "Valid values for service_endpoints are 'public', 'public-and-private', and 'private'"
63+
}
64+
}
65+
variable "member_host_flavor" {
66+
type = string
67+
description = "The host flavor per member. [Learn more](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/database#host_flavor)."
68+
default = "multitenant"
69+
# Validation is done in the Terraform plan phase by the IBM provider, so no need to add extra validation here.
70+
}

0 commit comments

Comments
 (0)