Skip to content
This repository was archived by the owner on Jun 17, 2025. It is now read-only.

Commit def867a

Browse files
akocbekakocbekIBM
andauthored
feat: added new variable use_default_backup_encryption_key. This now means it is possible to have KMS encryption for your primary instance, and use the default encryption on the backup instance (#84)
Co-authored-by: Andrej <[email protected]>
1 parent 4502fb8 commit def867a

File tree

4 files changed

+35
-16
lines changed

4 files changed

+35
-16
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ To attach access management tags to resources in this module, you need the follo
8686
| <a name="input_admin_pass"></a> [admin\_pass](#input\_admin\_pass) | The password for the database administrator. If the admin password is null then the admin user ID cannot be accessed. More users can be specified in a user block. The admin password must be in the range of 10-32 characters. | `string` | `null` | no |
8787
| <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 |
8888
| <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 |
89-
| <a name="input_backup_encryption_key_crn"></a> [backup\_encryption\_key\_crn](#input\_backup\_encryption\_key\_crn) | The CRN of a Key Protect key that you want to use for encrypting the disk that holds deployment backups. Only used if var.kms\_encryption\_enabled is set to true. BYOK for backups is available only in US regions us-south and us-east, and in eu-de. Only keys in the us-south and eu-de are durable to region failures. To ensure that your backups are available even if a region failure occurs, use a key from us-south or eu-de. Hyper Protect Crypto Services for IBM Cloud Databases backups is not currently supported. If no value is passed here, the value passed for the 'kms\_key\_crn' variable is used. And if a HPCS value is passed for var.kms\_key\_crn, the database backup encryption uses the default encryption keys. | `string` | `null` | no |
89+
| <a name="input_backup_encryption_key_crn"></a> [backup\_encryption\_key\_crn](#input\_backup\_encryption\_key\_crn) | The CRN of a Key Protect key that you want to use for encrypting the disk that holds deployment backups. Only used if var.kms\_encryption\_enabled is set to true. BYOK for backups is available only in US regions us-south and us-east, and in eu-de. Only keys in the us-south and eu-de are durable to region failures. To ensure that your backups are available even if a region failure occurs, use a key from us-south or eu-de. Hyper Protect Crypto Services for IBM Cloud Databases backups is not currently supported. If no value is passed here, the value passed for the 'kms\_key\_crn' variable is used, unless 'use\_default\_backup\_encryption\_key' is set to 'true'. And if a HPCS value is passed for var.kms\_key\_crn, the database backup encryption uses the default encryption keys. | `string` | `null` | no |
9090
| <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 |
9191
| <a name="input_configuration"></a> [configuration](#input\_configuration) | Database configuration | <pre>object({<br> max_connections = optional(number)<br> max_prepared_transactions = optional(number)<br> deadlock_timeout = optional(number)<br> effective_io_concurrency = optional(number)<br> max_replication_slots = optional(number)<br> max_wal_senders = optional(number)<br> shared_buffers = optional(number)<br> synchronous_commit = optional(string)<br> wal_level = optional(string)<br> archive_timeout = optional(number)<br> log_min_duration_statement = optional(number)<br> })</pre> | `null` | no |
9292
| <a name="input_edb_version"></a> [edb\_version](#input\_edb\_version) | Version of the Enterprise DB instance to provision. If no value is passed, the current preferred version of IBM Cloud Databases is used. | `string` | `null` | no |
@@ -108,6 +108,7 @@ To attach access management tags to resources in this module, you need the follo
108108
| <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 |
109109
| <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 |
110110
| <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 Enterprise 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 |
111+
| <a name="input_use_default_backup_encryption_key"></a> [use\_default\_backup\_encryption\_key](#input\_use\_default\_backup\_encryption\_key) | Set to true to use default ICD randomly generated keys. | `bool` | `false` | no |
111112
| <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 Enterprise Db instance. This blocks creates native enterprise database users, more info on that can be found here https://cloud.ibm.com/docs/databases-for-enterprisedb?topic=databases-for-enterprisedb-user-management&interface=api | <pre>list(object({<br> name = string<br> password = string # pragma: allowlist secret<br> type = string # "type" is required to generate the connection string for the outputs.<br> role = optional(string)<br> }))</pre> | `[]` | no |
112113

113114
### Outputs

main.tf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ locals {
1212
validate_kms_vars = var.kms_encryption_enabled && var.kms_key_crn == null && var.backup_encryption_key_crn == null ? tobool("When setting var.kms_encryption_enabled to true, a value must be passed for var.kms_key_crn and/or var.backup_encryption_key_crn") : true
1313
# tflint-ignore: terraform_unused_declarations
1414
validate_auth_policy = var.kms_encryption_enabled && var.skip_iam_authorization_policy == false && var.existing_kms_instance_guid == null ? tobool("When var.skip_iam_authorization_policy is set to false, and var.kms_encryption_enabled to true, a value must be passed for var.existing_kms_instance_guid in order to create the auth policy.") : true
15+
# tflint-ignore: terraform_unused_declarations
16+
validate_backup_key = var.backup_encryption_key_crn != null && var.use_default_backup_encryption_key == true ? tobool("When passing a value for 'backup_encryption_key_crn' you cannot set 'use_default_backup_encryption_key' to 'true'") : true
1517

1618
# If no value passed for 'backup_encryption_key_crn' use the value of 'kms_key_crn'. If this is a HPCS key (which is not currently supported for backup encryption), default to 'null' meaning encryption is done using randomly generated keys
1719
# More info https://cloud.ibm.com/docs/cloud-databases?topic=cloud-databases-hpcs
18-
backup_encryption_key_crn = var.backup_encryption_key_crn != null ? var.backup_encryption_key_crn : (can(regex(".*kms.*", var.kms_key_crn)) ? var.kms_key_crn : null)
20+
backup_encryption_key_crn = var.use_default_backup_encryption_key == true ? null : (var.backup_encryption_key_crn != null ? var.backup_encryption_key_crn : (can(regex(".*kms.*", var.kms_key_crn)) ? var.kms_key_crn : null))
1921

2022
# Determine if auto scaling is enabled
2123
auto_scaling_enabled = var.auto_scaling == null ? [] : [1]

module-metadata.json

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@
5353
],
5454
"pos": {
5555
"filename": "variables.tf",
56-
"line": 258
56+
"line": 264
5757
}
5858
},
5959
"backup_encryption_key_crn": {
6060
"name": "backup_encryption_key_crn",
6161
"type": "string",
62-
"description": "The CRN of a Key Protect key that you want to use for encrypting the disk that holds deployment backups. Only used if var.kms_encryption_enabled is set to true. BYOK for backups is available only in US regions us-south and us-east, and in eu-de. Only keys in the us-south and eu-de are durable to region failures. To ensure that your backups are available even if a region failure occurs, use a key from us-south or eu-de. Hyper Protect Crypto Services for IBM Cloud Databases backups is not currently supported. If no value is passed here, the value passed for the 'kms_key_crn' variable is used. And if a HPCS value is passed for var.kms_key_crn, the database backup encryption uses the default encryption keys.",
62+
"description": "The CRN of a Key Protect key that you want to use for encrypting the disk that holds deployment backups. Only used if var.kms_encryption_enabled is set to true. BYOK for backups is available only in US regions us-south and us-east, and in eu-de. Only keys in the us-south and eu-de are durable to region failures. To ensure that your backups are available even if a region failure occurs, use a key from us-south or eu-de. Hyper Protect Crypto Services for IBM Cloud Databases backups is not currently supported. If no value is passed here, the value passed for the 'kms_key_crn' variable is used, unless 'use_default_backup_encryption_key' is set to 'true'. And if a HPCS value is passed for var.kms_key_crn, the database backup encryption uses the default encryption keys.",
6363
"pos": {
6464
"filename": "variables.tf",
6565
"line": 212
@@ -79,7 +79,7 @@
7979
],
8080
"pos": {
8181
"filename": "variables.tf",
82-
"line": 238
82+
"line": 244
8383
}
8484
},
8585
"configuration": {
@@ -117,7 +117,7 @@
117117
],
118118
"pos": {
119119
"filename": "variables.tf",
120-
"line": 228
120+
"line": 234
121121
},
122122
"immutable": true,
123123
"computed": true
@@ -210,7 +210,7 @@
210210
],
211211
"pos": {
212212
"filename": "variables.tf",
213-
"line": 275
213+
"line": 281
214214
}
215215
},
216216
"pitr_time": {
@@ -222,7 +222,7 @@
222222
],
223223
"pos": {
224224
"filename": "variables.tf",
225-
"line": 281
225+
"line": 287
226226
}
227227
},
228228
"plan_validation": {
@@ -340,6 +340,16 @@
340340
"type": "bool",
341341
"description": "Set to true to skip the creation of an IAM authorization policy that permits all Enterprise 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.",
342342
"default": false,
343+
"pos": {
344+
"filename": "variables.tf",
345+
"line": 228
346+
}
347+
},
348+
"use_default_backup_encryption_key": {
349+
"name": "use_default_backup_encryption_key",
350+
"type": "bool",
351+
"description": "Set to true to use default ICD randomly generated keys.",
352+
"default": false,
343353
"pos": {
344354
"filename": "variables.tf",
345355
"line": 222
@@ -490,7 +500,7 @@
490500
},
491501
"pos": {
492502
"filename": "main.tf",
493-
"line": 50
503+
"line": 52
494504
}
495505
},
496506
"ibm_iam_authorization_policy.kms_policy": {
@@ -508,7 +518,7 @@
508518
},
509519
"pos": {
510520
"filename": "main.tf",
511-
"line": 32
521+
"line": 34
512522
}
513523
},
514524
"ibm_resource_key.service_credentials": {
@@ -523,7 +533,7 @@
523533
},
524534
"pos": {
525535
"filename": "main.tf",
526-
"line": 190
536+
"line": 192
527537
}
528538
},
529539
"ibm_resource_tag.enterprisedb_tag": {
@@ -539,7 +549,7 @@
539549
},
540550
"pos": {
541551
"filename": "main.tf",
542-
"line": 141
552+
"line": 143
543553
}
544554
},
545555
"time_sleep.wait_for_authorization_policy": {
@@ -551,7 +561,7 @@
551561
},
552562
"pos": {
553563
"filename": "main.tf",
554-
"line": 43
564+
"line": 45
555565
}
556566
}
557567
},
@@ -571,7 +581,7 @@
571581
},
572582
"pos": {
573583
"filename": "main.tf",
574-
"line": 218
584+
"line": 220
575585
}
576586
}
577587
},
@@ -650,7 +660,7 @@
650660
},
651661
"pos": {
652662
"filename": "main.tf",
653-
"line": 151
663+
"line": 153
654664
}
655665
}
656666
}

variables.tf

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,14 +211,20 @@ variable "kms_key_crn" {
211211

212212
variable "backup_encryption_key_crn" {
213213
type = string
214-
description = "The CRN of a Key Protect key that you want to use for encrypting the disk that holds deployment backups. Only used if var.kms_encryption_enabled is set to true. BYOK for backups is available only in US regions us-south and us-east, and in eu-de. Only keys in the us-south and eu-de are durable to region failures. To ensure that your backups are available even if a region failure occurs, use a key from us-south or eu-de. Hyper Protect Crypto Services for IBM Cloud Databases backups is not currently supported. If no value is passed here, the value passed for the 'kms_key_crn' variable is used. And if a HPCS value is passed for var.kms_key_crn, the database backup encryption uses the default encryption keys."
214+
description = "The CRN of a Key Protect key that you want to use for encrypting the disk that holds deployment backups. Only used if var.kms_encryption_enabled is set to true. BYOK for backups is available only in US regions us-south and us-east, and in eu-de. Only keys in the us-south and eu-de are durable to region failures. To ensure that your backups are available even if a region failure occurs, use a key from us-south or eu-de. Hyper Protect Crypto Services for IBM Cloud Databases backups is not currently supported. If no value is passed here, the value passed for the 'kms_key_crn' variable is used, unless 'use_default_backup_encryption_key' is set to 'true'. And if a HPCS value is passed for var.kms_key_crn, the database backup encryption uses the default encryption keys."
215215
default = null
216216
validation {
217217
condition = var.backup_encryption_key_crn == null ? true : length(regexall("^crn:v1:bluemix:public:kms:(us-south|us-east|eu-de):a/[[:xdigit:]]{32}:[[:xdigit:]]{8}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{12}:key:[[:xdigit:]]{8}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{12}$", var.backup_encryption_key_crn)) > 0
218218
error_message = "Valid values for backup_encryption_key_crn is null or a Key Protect key CRN from us-south, us-east or eu-de"
219219
}
220220
}
221221

222+
variable "use_default_backup_encryption_key" {
223+
type = bool
224+
description = "Set to true to use default ICD randomly generated keys."
225+
default = false
226+
}
227+
222228
variable "skip_iam_authorization_policy" {
223229
type = bool
224230
description = "Set to true to skip the creation of an IAM authorization policy that permits all Enterprise 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."

0 commit comments

Comments
 (0)