Skip to content

Commit 0ef29f8

Browse files
authored
feat: major inplace upgrade, deletion protection (#665)
1 parent 2b2769c commit 0ef29f8

25 files changed

+205
-118
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ To attach access management tags to resources in this module, you need the follo
101101
| <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 |
102102
| <a name="input_configuration"></a> [configuration](#input\_configuration) | Database configuration parameters, see https://cloud.ibm.com/docs/databases-for-postgresql?topic=databases-for-postgresql-changing-configuration&interface=api for more details. | <pre>object({<br/> shared_buffers = optional(number)<br/> max_connections = optional(number)<br/> # below field gives error when sent to provider<br/> # tracking issue: https://github.com/IBM-Cloud/terraform-provider-ibm/issues/5403<br/> # max_locks_per_transaction = optional(number)<br/> max_prepared_transactions = optional(number)<br/> synchronous_commit = optional(string)<br/> effective_io_concurrency = optional(number)<br/> deadlock_timeout = optional(number)<br/> log_connections = optional(string)<br/> log_disconnections = optional(string)<br/> log_min_duration_statement = optional(number)<br/> tcp_keepalives_idle = optional(number)<br/> tcp_keepalives_interval = optional(number)<br/> tcp_keepalives_count = optional(number)<br/> archive_timeout = optional(number)<br/> wal_level = optional(string)<br/> max_replication_slots = optional(number)<br/> max_wal_senders = optional(number)<br/> })</pre> | `null` | no |
103103
| <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-postgresql?topic=databases-for-postgresql-resources-scaling) | `number` | `0` | no |
104+
| <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 |
104105
| <a name="input_disk_mb"></a> [disk\_mb](#input\_disk\_mb) | Allocated disk per member. [Learn more](https://cloud.ibm.com/docs/databases-for-postgresql?topic=databases-for-postgresql-resources-scaling) | `number` | `5120` | no |
105106
| <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 |
106107
| <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 |
@@ -117,10 +118,12 @@ To attach access management tags to resources in this module, you need the follo
117118
| <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 |
118119
| <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 PostgreSQL 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 |
119120
| <a name="input_tags"></a> [tags](#input\_tags) | Optional list of tags to be added to the PostgreSQL instance. | `list(string)` | `[]` | no |
121+
| <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 |
120122
| <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 |
121123
| <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 |
122124
| <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 |
123125
| <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 Postgres instance. This blocks creates native postgres database users, more info on that can be found here https://cloud.ibm.com/docs/databases-for-postgresql?topic=databases-for-postgresql-user-management&interface=ui | <pre>list(object({<br/> name = string<br/> password = string # pragma: allowlist secret<br/> type = optional(string)<br/> role = optional(string)<br/> }))</pre> | `[]` | no |
126+
| <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 |
124127

125128
### Outputs
126129

examples/backup/catalogValidationValues.json.template

Lines changed: 0 additions & 6 deletions
This file was deleted.

examples/backup/main.tf

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,13 @@ module "restored_icd_postgresql" {
3333
# remove the above line and uncomment the below 2 lines to consume the module from the registry
3434
# source = "terraform-ibm-modules/icd-postgresql/ibm"
3535
# version = "X.Y.Z" # Replace "X.Y.Z" with a release version to lock into a specific release
36-
resource_group_id = module.resource_group.resource_group_id
37-
name = "${var.prefix}-postgres-restored"
38-
postgresql_version = var.postgresql_version
39-
region = var.region
40-
tags = var.resource_tags
41-
access_tags = var.access_tags
42-
member_host_flavor = "multitenant"
43-
backup_crn = var.postgresql_db_backup_crn == null ? data.ibm_database_backups.backup_database[0].backups[0].backup_id : var.postgresql_db_backup_crn
36+
resource_group_id = module.resource_group.resource_group_id
37+
name = "${var.prefix}-postgres-restored"
38+
postgresql_version = var.postgresql_version
39+
region = var.region
40+
tags = var.resource_tags
41+
access_tags = var.access_tags
42+
deletion_protection = false
43+
member_host_flavor = "multitenant"
44+
backup_crn = var.postgresql_db_backup_crn == null ? data.ibm_database_backups.backup_database[0].backups[0].backup_id : var.postgresql_db_backup_crn
4445
}

examples/basic/catalogValidationValues.json.template

Lines changed: 0 additions & 6 deletions
This file was deleted.

examples/basic/main.tf

Lines changed: 23 additions & 21 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-postgresql/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}-data-store"
24-
postgresql_version = var.postgresql_version
25-
region = var.region
26-
tags = var.resource_tags
27-
access_tags = var.access_tags
28-
service_endpoints = var.service_endpoints
29-
member_host_flavor = var.member_host_flavor
22+
resource_group_id = module.resource_group.resource_group_id
23+
name = "${var.prefix}-data-store"
24+
region = var.region
25+
postgresql_version = var.postgresql_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
"postgresql_admin" : "Administrator",
3233
"postgresql_operator" : "Operator",
@@ -54,17 +55,18 @@ resource "time_sleep" "wait_time" {
5455
##############################################################################
5556

5657
module "read_only_replica_postgresql_db" {
57-
count = var.read_only_replicas_count
58-
source = "../.."
59-
resource_group_id = module.resource_group.resource_group_id
60-
name = "${var.prefix}-read-only-replica-${count.index}"
61-
region = var.region
62-
tags = var.resource_tags
63-
access_tags = var.access_tags
64-
postgresql_version = var.postgresql_version
65-
remote_leader_crn = module.database.crn
66-
member_host_flavor = "multitenant"
67-
memory_mb = 4096 # Must be an increment of 384 megabytes. The minimum size of a read-only replica is 2 GB RAM, new hosting model minimum is 4 GB RAM.
68-
disk_mb = 5120 # Must be an increment of 512 megabytes. The minimum size of a read-only replica is 5 GB of disk
69-
depends_on = [time_sleep.wait_time]
58+
count = var.read_only_replicas_count
59+
source = "../.."
60+
resource_group_id = module.resource_group.resource_group_id
61+
name = "${var.prefix}-read-only-replica-${count.index}"
62+
region = var.region
63+
tags = var.resource_tags
64+
access_tags = var.access_tags
65+
postgresql_version = var.postgresql_version
66+
remote_leader_crn = module.database.crn
67+
deletion_protection = false
68+
member_host_flavor = "multitenant"
69+
memory_mb = 4096 # Must be an increment of 384 megabytes. The minimum size of a read-only replica is 2 GB RAM, new hosting model minimum is 4 GB RAM.
70+
disk_mb = 5120 # Must be an increment of 512 megabytes. The minimum size of a read-only replica is 5 GB of disk
71+
depends_on = [time_sleep.wait_time]
7072
}

examples/basic/outputs.tf

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ output "id" {
66
value = module.database.id
77
}
88

9+
output "postgresql_crn" {
10+
description = "Postgresql CRN"
11+
value = module.database.crn
12+
}
13+
914
output "version" {
1015
description = "Postgresql instance version"
1116
value = module.database.version
@@ -31,8 +36,3 @@ output "certificate_base64" {
3136
value = module.database.certificate_base64
3237
sensitive = true
3338
}
34-
35-
output "postgresql_crn" {
36-
description = "Postgresql CRN"
37-
value = module.database.crn
38-
}

examples/basic/variables.tf

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,14 @@ 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"
10+
default = "us-south"
1011
}
1112

1213
variable "prefix" {
1314
type = string
1415
description = "Prefix to append to all resources created by this example"
15-
}
16-
17-
variable "postgresql_version" {
18-
description = "Version of the postgresql instance. If no value passed, the current ICD preferred version is used."
19-
type = string
20-
default = null
16+
default = "pg"
2117
}
2218

2319
variable "resource_group" {
@@ -26,34 +22,21 @@ variable "resource_group" {
2622
default = null
2723
}
2824

29-
variable "resource_tags" {
30-
type = list(string)
31-
description = "Optional list of tags to be added to created resources"
32-
default = []
33-
}
34-
3525
variable "access_tags" {
3626
type = list(string)
3727
description = "A list of access tags to apply to the PostgreSQL instance created by the module, see https://cloud.ibm.com/docs/account?topic=account-access-tags-tutorial for more details"
3828
default = []
3929
}
4030

41-
variable "read_only_replicas_count" {
42-
type = number
43-
description = "Number of read-only replicas per leader"
44-
default = 1
45-
validation {
46-
condition = alltrue([
47-
var.read_only_replicas_count >= 1,
48-
var.read_only_replicas_count <= 5
49-
])
50-
error_message = "There is a limit of five read-only replicas per leader"
51-
}
31+
variable "resource_tags" {
32+
type = list(string)
33+
description = "Optional list of tags to be added to created resources"
34+
default = []
5235
}
5336

54-
variable "member_host_flavor" {
37+
variable "postgresql_version" {
5538
type = string
56-
description = "Allocated host flavor per member. For more information, see https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/database#host_flavor"
39+
description = "Version of the postgresql instance. If no value passed, the current ICD preferred version is used."
5740
default = null
5841
}
5942

@@ -67,3 +50,23 @@ variable "service_endpoints" {
6750
error_message = "Valid values for service_endpoints are 'public', 'public-and-private', and 'private'"
6851
}
6952
}
53+
54+
variable "member_host_flavor" {
55+
type = string
56+
description = "The host flavor per member. [Learn more](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/database#host_flavor)."
57+
default = "multitenant"
58+
# Validation is done in the Terraform plan phase by the IBM provider, so no need to add extra validation here.
59+
}
60+
61+
variable "read_only_replicas_count" {
62+
type = number
63+
description = "Number of read-only replicas per leader"
64+
default = 1
65+
validation {
66+
condition = alltrue([
67+
var.read_only_replicas_count >= 1,
68+
var.read_only_replicas_count <= 5
69+
])
70+
error_message = "There is a limit of five read-only replicas per leader"
71+
}
72+
}

examples/complete/catalogValidationValues.json.template

Lines changed: 0 additions & 6 deletions
This file was deleted.

examples/complete/main.tf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,9 @@ module "icd_postgresql" {
124124
"postgressql_viewer" : "Viewer",
125125
"postgressql_editor" : "Editor",
126126
}
127-
access_tags = var.access_tags
128-
member_host_flavor = "multitenant"
127+
access_tags = var.access_tags
128+
member_host_flavor = "multitenant"
129+
deletion_protection = false
129130
# Example of setting configuration - none of the below is mandatory - those settings are set in this example for illustation purpose and ensure path is exercised in automated test using this example.
130131
configuration = {
131132
shared_buffers = 32000

examples/fscloud/catalogValidationValues.json.template

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)