Skip to content

Commit 6463f5f

Browse files
authored
fix: add extra validation around KMS inputs (#188)
1 parent 56e623e commit 6463f5f

File tree

17 files changed

+78
-102
lines changed

17 files changed

+78
-102
lines changed

README.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ module "postgresql_db" {
2929
```
3030

3131
## Required IAM access policies
32-
3332
You need the following permissions to run this module.
3433

3534
- Account Management
@@ -41,7 +40,7 @@ You need the following permissions to run this module.
4140

4241
- [ Restore from backup example](examples/backup)
4342
- [ Basic with read-only replica example](examples/basic)
44-
- [ Complete example with BYOK encryption, autoscaling, CBR rules, VPE creation, and read-only replica provisioning](examples/complete)
43+
- [ Complete example with BYOK encryption, autoscaling, CBR rules and VPE creation](examples/complete)
4544
- [ Financial Services Cloud profile example](examples/fscloud)
4645
- [ Point in time recovery example (PITR)](examples/pitr)
4746
<!-- END EXAMPLES HOOK -->
@@ -73,18 +72,18 @@ You need the following permissions to run this module.
7372
|------|-------------|------|---------|:--------:|
7473
| <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> cpu = object({<br> rate_increase_percent = optional(number, 10)<br> rate_limit_count_per_member = optional(number, 20)<br> rate_period_seconds = optional(number, 900)<br> rate_units = optional(string, "count")<br> })<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 |
7574
| <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 |
76-
| <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 disk that holds deployment backups. Only used if var.kms\_encryption\_enabled is set to true. If no value passed, the value passed for the 'kms\_key\_crn' variable will be used. BYOK for backups is available only in US regions us-south and us-east, and 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, you must use a key from us-south or eu-de. Take note that Hyper Protect Crypto Services for IBM Cloud® Databases backups is not currently supported, so if no value is passed here, but a HPCS value is passed for var.kms\_key\_crn, databases backup encryption will use the default encryption keys. | `string` | `null` | no |
75+
| <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 |
7776
| <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 |
7877
| <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 |
79-
| <a name="input_existing_kms_instance_guid"></a> [existing\_kms\_instance\_guid](#input\_existing\_kms\_instance\_guid) | The GUID of the Hyper Protect or Key Protect instance in which the key specified in var.kms\_key\_crn and var.backup\_encryption\_key\_crn is coming from. Only required if var.kms\_encryption\_enabled is 'true', var.skip\_iam\_authorization\_policy is 'false', and passing a value for var.kms\_key\_crn and/or var.backup\_encryption\_key\_crn. | `string` | `null` | no |
78+
| <a name="input_existing_kms_instance_guid"></a> [existing\_kms\_instance\_guid](#input\_existing\_kms\_instance\_guid) | The GUID of the Hyper Protect Crypto Services or Key Protect instance in which the key specified in var.kms\_key\_crn and var.backup\_encryption\_key\_crn is coming from. Required only if var.kms\_encryption\_enabled is set to true, var.skip\_iam\_authorization\_policy is set to false, and you pass a value for var.kms\_key\_crn, var.backup\_encryption\_key\_crn, or both. | `string` | `null` | no |
8079
| <a name="input_kms_encryption_enabled"></a> [kms\_encryption\_enabled](#input\_kms\_encryption\_enabled) | Set this to true to control the encryption keys used to encrypt the data that you store in IBM Cloud® Databases. If set to false, the data is encrypted by using randomly generated keys. For more info on Key Protect integration, see https://cloud.ibm.com/docs/cloud-databases?topic=cloud-databases-key-protect. For more info on HPCS integration, see https://cloud.ibm.com/docs/cloud-databases?topic=cloud-databases-hpcs | `bool` | `false` | no |
81-
| <a name="input_kms_key_crn"></a> [kms\_key\_crn](#input\_kms\_key\_crn) | The root key CRN of a Key Management Services like Key Protect or Hyper Protect Crypto Service (HPCS) that you want to use for disk encryption. Only used if var.kms\_encryption\_enabled is set to true. | `string` | `null` | no |
82-
| <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. See the following doc for supported values: https://cloud.ibm.com/docs/databases-for-postgresql?topic=databases-for-postgresql-resources-scaling | `number` | `0` | no |
83-
| <a name="input_member_disk_mb"></a> [member\_disk\_mb](#input\_member\_disk\_mb) | Allocated disk per-member. See the following doc for supported values: https://cloud.ibm.com/docs/databases-for-postgresql?topic=databases-for-postgresql-resources-scaling | `number` | `5120` | no |
80+
| <a name="input_kms_key_crn"></a> [kms\_key\_crn](#input\_kms\_key\_crn) | The root key CRN of a Key Management Services like Key Protect or Hyper Protect Crypto Services (HPCS) that you want to use for disk encryption. Only used if var.kms\_encryption\_enabled is set to true. | `string` | `null` | no |
81+
| <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. For more information, see https://cloud.ibm.com/docs/databases-for-postgresql?topic=databases-for-postgresql-resources-scaling | `number` | `0` | no |
82+
| <a name="input_member_disk_mb"></a> [member\_disk\_mb](#input\_member\_disk\_mb) | Allocated disk per member. For more information, see https://cloud.ibm.com/docs/databases-for-postgresql?topic=databases-for-postgresql-resources-scaling | `number` | `5120` | no |
8483
| <a name="input_member_memory_mb"></a> [member\_memory\_mb](#input\_member\_memory\_mb) | Allocated memory per-member. See the following doc for supported values: https://cloud.ibm.com/docs/databases-for-postgresql?topic=databases-for-postgresql-resources-scaling | `number` | `1024` | no |
8584
| <a name="input_members"></a> [members](#input\_members) | Allocated number of members. Members can be scaled up but not down. | `number` | `2` | no |
8685
| <a name="input_name"></a> [name](#input\_name) | The name to give the Postgresql instance. | `string` | n/a | yes |
87-
| <a name="input_pg_version"></a> [pg\_version](#input\_pg\_version) | Version of the PostgreSQL instance to provision. | `string` | `null` | no |
86+
| <a name="input_pg_version"></a> [pg\_version](#input\_pg\_version) | Version of the PostgreSQL instance to provision. If no value is passed, the current preferred version of IBM Cloud Databases is used. | `string` | `null` | no |
8887
| <a name="input_pitr_id"></a> [pitr\_id](#input\_pitr\_id) | (Optional) The ID of the source deployment PostgreSQL instance that you want to recover back to. The PostgreSQL instance is expected to be in an up and in running state. | `string` | `null` | no |
8988
| <a name="input_pitr_time"></a> [pitr\_time](#input\_pitr\_time) | (Optional) The timestamp in UTC format (%Y-%m-%dT%H:%M:%SZ) that you want to restore to. To retrieve the timestamp, run the command (ibmcloud cdb postgresql earliest-pitr-timestamp <deployment name or CRN>). For more info on Point-in-time Recovery, see https://cloud.ibm.com/docs/databases-for-postgresql?topic=databases-for-postgresql-pitr | `string` | `null` | no |
9089
| <a name="input_plan_validation"></a> [plan\_validation](#input\_plan\_validation) | Enable or disable validating the database parameters for PostgreSQL during the plan phase. | `bool` | `true` | no |
@@ -94,7 +93,7 @@ You need the following permissions to run this module.
9493
| <a name="input_resource_tags"></a> [resource\_tags](#input\_resource\_tags) | Optional list of tags to be added to the PostgreSQL instance and the associated service credentials (if creating). | `list(string)` | `[]` | no |
9594
| <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 |
9695
| <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 |
97-
| <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 PostgreSQL database instances in the given resource group to read the encryption key from the Hyper Protect or Key Protect instance passed in var.existing\_kms\_instance\_guid. If set to 'false', a value must be passed for var.existing\_kms\_instance\_guid. No policy is created if var.kms\_encryption\_enabled is set to 'false'. | `bool` | `false` | no |
96+
| <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 PostgreSQL database instances in the resource group to read the encryption key from the Hyper Protect Crypto Services (HPCS) instance. If set to false, pass in a value for the HPCS instance in the var.existing\_kms\_instance\_guid variable. In addition, no policy is created if var.kms\_encryption\_enabled is set to false. | `bool` | `false` | no |
9897

9998
## Outputs
10099

examples/backup/variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ variable "prefix" {
1717
}
1818

1919
variable "pg_version" {
20-
description = "Version of the postgresql instance"
20+
description = "Version of the postgresql instance. If no value passed, the current ICD preferred version is used."
2121
type = string
2222
default = null
2323
}

examples/basic/variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ variable "prefix" {
1717
}
1818

1919
variable "pg_version" {
20-
description = "Version of the postgresql instance"
20+
description = "Version of the postgresql instance. If no value passed, the current ICD preferred version is used."
2121
type = string
2222
default = null
2323
}

examples/complete/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
# Complete example with BYOK encryption, autoscaling, CBR rules, VPE creation, and read-only replica provisioning
1+
# Complete example with BYOK encryption, autoscaling, CBR rules and VPE creation
22

33
An end-to-end example that does the following:
44

55
- Create a new resource group if one is not passed in.
66
- Create Key Protect instance with root key.
77
- Create a new ICD PostgreSQL database instance with auto-scaling and BYOK encryption enabled.
8+
- Create service credentials for the database instance.
89
- Create a Virtual Private Cloud (VPC).
910
- Create Context Based Restriction (CBR) to only allow Postgresql to be accessible from the VPC.
1011
- Create a security group and a VPE for the PostgreSQL instance.

examples/complete/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ module "postgresql_db" {
7171
resource_group_id = module.resource_group.resource_group_id
7272
name = "${var.prefix}-postgres"
7373
region = var.region
74-
service_endpoints = "private"
7574
pg_version = var.pg_version
7675
kms_encryption_enabled = true
7776
kms_key_crn = module.key_protect_all_inclusive.keys["icd-pg.${var.prefix}-pg"].crn
@@ -133,6 +132,7 @@ resource "ibm_is_virtual_endpoint_gateway" "pgvpe" {
133132
]
134133
}
135134

135+
# wait 30 secs after security group is destroyed before destroying VPE to workaround race condition
136136
resource "time_sleep" "wait_30_seconds" {
137137
depends_on = [ibm_is_security_group.sg1]
138138
destroy_duration = "30s"

examples/complete/variables.tf

Lines changed: 5 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ variable "resource_tags" {
2929
}
3030

3131
variable "pg_version" {
32-
description = "Version of the postgresql instance"
32+
description = "Version of the PostgreSQL instance. If no value is passed, the current preferred version of IBM Cloud Databases is used."
3333
type = string
3434
default = null
3535
}
@@ -38,9 +38,10 @@ variable "service_credential_names" {
3838
description = "Map of name, role for service credentials that you want to create for the database"
3939
type = map(string)
4040
default = {
41-
"postgressql_credential_microservices" : "Administrator",
42-
"postgressql_credential_dev_1" : "Administrator",
43-
"postgressql_credential_dev_2" : "Administrator"
41+
"postgressql_admin" : "Administrator",
42+
"postgressql_operator" : "Operator",
43+
"postgressql_viewer" : "Viewer",
44+
"postgressql_editor" : "Editor",
4445
}
4546
}
4647

@@ -85,42 +86,3 @@ variable "auto_scaling" {
8586
}
8687
}
8788
}
88-
89-
variable "replica_member_memory_mb" {
90-
type = number
91-
description = "Memory allocation required for postgresql read-only replica database"
92-
default = "3072"
93-
validation {
94-
condition = alltrue([
95-
var.replica_member_memory_mb >= 3072,
96-
var.replica_member_memory_mb <= 114688
97-
])
98-
error_message = "member group memory must be >= 3072 and <= 114688 in increments of 384"
99-
}
100-
}
101-
102-
variable "replica_member_disk_mb" {
103-
type = number
104-
description = "Disk allocation required for postgresql read-only replica database"
105-
default = "15360"
106-
validation {
107-
condition = alltrue([
108-
var.replica_member_disk_mb >= 15360,
109-
var.replica_member_disk_mb <= 4194304
110-
])
111-
error_message = "member group disk must be >= 15360 and <= 4194304 in increments of 1536"
112-
}
113-
}
114-
115-
variable "replica_member_cpu_count" {
116-
type = number
117-
description = "CPU allocation required for the postgresql read-only replica database"
118-
default = "9"
119-
validation {
120-
condition = alltrue([
121-
var.replica_member_cpu_count >= 9,
122-
var.replica_member_cpu_count <= 28
123-
])
124-
error_message = "member group cpu must be >= 9 and <= 28 in increments of 1"
125-
}
126-
}

examples/fscloud/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ An end-to-end example that uses the [Profile for IBM Cloud Framework for Financi
55
The example uses the IBM Cloud Terraform provider to create the following infrastructure:
66

77
- A resource group, if one is not passed in.
8-
- An IAM authorization between the PostgreSQL database resource group and the Hyper Protect Crypto Services permanent instance.
9-
- An IBM Cloud Databases PostgreSQL database instance and credentials that are encrypted with the Hyper Protect Crypto Services resources that are passed in.
8+
- An IAM authorization between all PostgreSQL database instances in the given resource group, and the Hyper Protect Crypto Services instance that is passed in.
9+
- An IBM Cloud Databases PostgreSQL database instance that is encrypted with the Hyper Protect Crypto Services root key that is passed in.
10+
- Service Credentials for the PostgreSQL database instance.
1011
- A sample virtual private cloud (VPC).
11-
- A context-based restriction (CBR) rule to prevent access from the VPC except to the PostgreSQL database.
12+
- A context-based restriction (CBR) rule to only allow PostgreSQL to be accessible from within the VPC.
1213

1314
:exclamation: **Important:** In this example, only the IBM Cloud Databases for PostgreSQL instance complies with the IBM Cloud Framework for Financial Services. Other parts of the infrastructure do not necessarily comply.
1415

1516
## Before you begin
1617

17-
- You need Hyper Protect Crypto Service instances available in the two regions that you want to deploy your PostgreSQL database instance.
18-
- You must deploy into an account that complies with the framework.
18+
- You need a Hyper Protect Crypto Services instance and root key available in the region that you want to deploy your PostgreSQL database instance to.

examples/fscloud/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ module "postgresql_db" {
6060
kms_key_crn = var.kms_key_crn
6161
existing_kms_instance_guid = var.existing_kms_instance_guid
6262
resource_tags = var.resource_tags
63+
service_credential_names = var.service_credential_names
6364
cbr_rules = [
6465
{
6566
description = "${var.prefix}-postgres access only from vpc"

0 commit comments

Comments
 (0)