diff --git a/README.md b/README.md index be2a3d2f..d66969a0 100644 --- a/README.md +++ b/README.md @@ -101,6 +101,7 @@ To attach access management tags to resources in this module, you need the follo | [cbr\_rules](#input\_cbr\_rules) | (Optional, list) List of CBR rules to create |
list(object({
description = string
account_id = string
rule_contexts = list(object({
attributes = optional(list(object({
name = string
value = string
}))) }))
enforcement_mode = string
tags = optional(list(object({
name = string
value = string
})))
})) | `[]` | no |
| [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. | object({
shared_buffers = optional(number)
max_connections = optional(number)
# below field gives error when sent to provider
# tracking issue: https://github.com/IBM-Cloud/terraform-provider-ibm/issues/5403
# max_locks_per_transaction = optional(number)
max_prepared_transactions = optional(number)
synchronous_commit = optional(string)
effective_io_concurrency = optional(number)
deadlock_timeout = optional(number)
log_connections = optional(string)
log_disconnections = optional(string)
log_min_duration_statement = optional(number)
tcp_keepalives_idle = optional(number)
tcp_keepalives_interval = optional(number)
tcp_keepalives_count = optional(number)
archive_timeout = optional(number)
wal_level = optional(string)
max_replication_slots = optional(number)
max_wal_senders = optional(number)
}) | `null` | no |
| [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 |
+| [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 |
| [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 |
| [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 |
| [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
| [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 |
| [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 |
| [tags](#input\_tags) | Optional list of tags to be added to the PostgreSQL instance. | `list(string)` | `[]` | no |
+| [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 |
| [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 |
| [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 |
| [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 |
| [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 | list(object({
name = string
password = string # pragma: allowlist secret
type = optional(string)
role = optional(string)
})) | `[]` | no |
+| [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 |
### Outputs
diff --git a/examples/backup/catalogValidationValues.json.template b/examples/backup/catalogValidationValues.json.template
deleted file mode 100644
index d761afae..00000000
--- a/examples/backup/catalogValidationValues.json.template
+++ /dev/null
@@ -1,6 +0,0 @@
-{
- "ibmcloud_api_key": $VALIDATION_APIKEY,
- "region": "us-south",
- "resource_tags": $TAGS,
- "prefix": $PREFIX
-}
diff --git a/examples/backup/main.tf b/examples/backup/main.tf
index c831b156..f6b8aaa4 100644
--- a/examples/backup/main.tf
+++ b/examples/backup/main.tf
@@ -33,12 +33,13 @@ module "restored_icd_postgresql" {
# remove the above line and uncomment the below 2 lines to consume the module from the registry
# source = "terraform-ibm-modules/icd-postgresql/ibm"
# version = "X.Y.Z" # Replace "X.Y.Z" with a release version to lock into a specific release
- resource_group_id = module.resource_group.resource_group_id
- name = "${var.prefix}-postgres-restored"
- postgresql_version = var.postgresql_version
- region = var.region
- tags = var.resource_tags
- access_tags = var.access_tags
- member_host_flavor = "multitenant"
- backup_crn = var.postgresql_db_backup_crn == null ? data.ibm_database_backups.backup_database[0].backups[0].backup_id : var.postgresql_db_backup_crn
+ resource_group_id = module.resource_group.resource_group_id
+ name = "${var.prefix}-postgres-restored"
+ postgresql_version = var.postgresql_version
+ region = var.region
+ tags = var.resource_tags
+ access_tags = var.access_tags
+ deletion_protection = false
+ member_host_flavor = "multitenant"
+ backup_crn = var.postgresql_db_backup_crn == null ? data.ibm_database_backups.backup_database[0].backups[0].backup_id : var.postgresql_db_backup_crn
}
diff --git a/examples/basic/catalogValidationValues.json.template b/examples/basic/catalogValidationValues.json.template
deleted file mode 100644
index d761afae..00000000
--- a/examples/basic/catalogValidationValues.json.template
+++ /dev/null
@@ -1,6 +0,0 @@
-{
- "ibmcloud_api_key": $VALIDATION_APIKEY,
- "region": "us-south",
- "resource_tags": $TAGS,
- "prefix": $PREFIX
-}
diff --git a/examples/basic/main.tf b/examples/basic/main.tf
index 6b3e80c6..8bbe2672 100644
--- a/examples/basic/main.tf
+++ b/examples/basic/main.tf
@@ -19,14 +19,15 @@ module "database" {
# remove the above line and uncomment the below 2 lines to consume the module from the registry
# source = "terraform-ibm-modules/icd-postgresql/ibm"
# version = "X.Y.Z" # Replace "X.Y.Z" with a release version to lock into a specific release
- resource_group_id = module.resource_group.resource_group_id
- name = "${var.prefix}-data-store"
- postgresql_version = var.postgresql_version
- region = var.region
- tags = var.resource_tags
- access_tags = var.access_tags
- service_endpoints = var.service_endpoints
- member_host_flavor = var.member_host_flavor
+ resource_group_id = module.resource_group.resource_group_id
+ name = "${var.prefix}-data-store"
+ region = var.region
+ postgresql_version = var.postgresql_version
+ access_tags = var.access_tags
+ tags = var.resource_tags
+ service_endpoints = var.service_endpoints
+ member_host_flavor = var.member_host_flavor
+ deletion_protection = false
service_credential_names = {
"postgresql_admin" : "Administrator",
"postgresql_operator" : "Operator",
@@ -54,17 +55,18 @@ resource "time_sleep" "wait_time" {
##############################################################################
module "read_only_replica_postgresql_db" {
- count = var.read_only_replicas_count
- source = "../.."
- resource_group_id = module.resource_group.resource_group_id
- name = "${var.prefix}-read-only-replica-${count.index}"
- region = var.region
- tags = var.resource_tags
- access_tags = var.access_tags
- postgresql_version = var.postgresql_version
- remote_leader_crn = module.database.crn
- member_host_flavor = "multitenant"
- 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.
- disk_mb = 5120 # Must be an increment of 512 megabytes. The minimum size of a read-only replica is 5 GB of disk
- depends_on = [time_sleep.wait_time]
+ count = var.read_only_replicas_count
+ source = "../.."
+ resource_group_id = module.resource_group.resource_group_id
+ name = "${var.prefix}-read-only-replica-${count.index}"
+ region = var.region
+ tags = var.resource_tags
+ access_tags = var.access_tags
+ postgresql_version = var.postgresql_version
+ remote_leader_crn = module.database.crn
+ deletion_protection = false
+ member_host_flavor = "multitenant"
+ 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.
+ disk_mb = 5120 # Must be an increment of 512 megabytes. The minimum size of a read-only replica is 5 GB of disk
+ depends_on = [time_sleep.wait_time]
}
diff --git a/examples/basic/outputs.tf b/examples/basic/outputs.tf
index 205652cd..30c74668 100644
--- a/examples/basic/outputs.tf
+++ b/examples/basic/outputs.tf
@@ -6,6 +6,11 @@ output "id" {
value = module.database.id
}
+output "postgresql_crn" {
+ description = "Postgresql CRN"
+ value = module.database.crn
+}
+
output "version" {
description = "Postgresql instance version"
value = module.database.version
@@ -31,8 +36,3 @@ output "certificate_base64" {
value = module.database.certificate_base64
sensitive = true
}
-
-output "postgresql_crn" {
- description = "Postgresql CRN"
- value = module.database.crn
-}
diff --git a/examples/basic/variables.tf b/examples/basic/variables.tf
index f40cfbd4..9dadb5c2 100644
--- a/examples/basic/variables.tf
+++ b/examples/basic/variables.tf
@@ -6,18 +6,14 @@ variable "ibmcloud_api_key" {
variable "region" {
type = string
- description = "Region to provision all resources created by this example."
+ description = "Region to provision all resources created by this example"
+ default = "us-south"
}
variable "prefix" {
type = string
description = "Prefix to append to all resources created by this example"
-}
-
-variable "postgresql_version" {
- description = "Version of the postgresql instance. If no value passed, the current ICD preferred version is used."
- type = string
- default = null
+ default = "pg"
}
variable "resource_group" {
@@ -26,34 +22,21 @@ variable "resource_group" {
default = null
}
-variable "resource_tags" {
- type = list(string)
- description = "Optional list of tags to be added to created resources"
- default = []
-}
-
variable "access_tags" {
type = list(string)
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"
default = []
}
-variable "read_only_replicas_count" {
- type = number
- description = "Number of read-only replicas per leader"
- default = 1
- validation {
- condition = alltrue([
- var.read_only_replicas_count >= 1,
- var.read_only_replicas_count <= 5
- ])
- error_message = "There is a limit of five read-only replicas per leader"
- }
+variable "resource_tags" {
+ type = list(string)
+ description = "Optional list of tags to be added to created resources"
+ default = []
}
-variable "member_host_flavor" {
+variable "postgresql_version" {
type = string
- description = "Allocated host flavor per member. For more information, see https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/database#host_flavor"
+ description = "Version of the postgresql instance. If no value passed, the current ICD preferred version is used."
default = null
}
@@ -67,3 +50,23 @@ variable "service_endpoints" {
error_message = "Valid values for service_endpoints are 'public', 'public-and-private', and 'private'"
}
}
+
+variable "member_host_flavor" {
+ type = string
+ description = "The host flavor per member. [Learn more](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/database#host_flavor)."
+ default = "multitenant"
+ # Validation is done in the Terraform plan phase by the IBM provider, so no need to add extra validation here.
+}
+
+variable "read_only_replicas_count" {
+ type = number
+ description = "Number of read-only replicas per leader"
+ default = 1
+ validation {
+ condition = alltrue([
+ var.read_only_replicas_count >= 1,
+ var.read_only_replicas_count <= 5
+ ])
+ error_message = "There is a limit of five read-only replicas per leader"
+ }
+}
diff --git a/examples/complete/catalogValidationValues.json.template b/examples/complete/catalogValidationValues.json.template
deleted file mode 100644
index d761afae..00000000
--- a/examples/complete/catalogValidationValues.json.template
+++ /dev/null
@@ -1,6 +0,0 @@
-{
- "ibmcloud_api_key": $VALIDATION_APIKEY,
- "region": "us-south",
- "resource_tags": $TAGS,
- "prefix": $PREFIX
-}
diff --git a/examples/complete/main.tf b/examples/complete/main.tf
index 078b45d9..f4fd9898 100644
--- a/examples/complete/main.tf
+++ b/examples/complete/main.tf
@@ -124,8 +124,9 @@ module "icd_postgresql" {
"postgressql_viewer" : "Viewer",
"postgressql_editor" : "Editor",
}
- access_tags = var.access_tags
- member_host_flavor = "multitenant"
+ access_tags = var.access_tags
+ member_host_flavor = "multitenant"
+ deletion_protection = false
# 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.
configuration = {
shared_buffers = 32000
diff --git a/examples/fscloud/catalogValidationValues.json.template b/examples/fscloud/catalogValidationValues.json.template
deleted file mode 100644
index eaf940f5..00000000
--- a/examples/fscloud/catalogValidationValues.json.template
+++ /dev/null
@@ -1,7 +0,0 @@
-{
- "ibmcloud_api_key": $VALIDATION_APIKEY,
- "region": "us-south",
- "resource_tags": $TAGS,
- "prefix": $PREFIX,
- "kms_key_crn": $HPCS_US_SOUTH_ROOT_KEY_CRN
-}
diff --git a/examples/fscloud/main.tf b/examples/fscloud/main.tf
index 876e4715..85ea5d89 100644
--- a/examples/fscloud/main.tf
+++ b/examples/fscloud/main.tf
@@ -72,7 +72,8 @@ module "postgresql_db" {
"postgressql_viewer" : "Viewer",
"postgressql_editor" : "Editor",
}
- access_tags = var.access_tags
+ access_tags = var.access_tags
+ deletion_protection = false
auto_scaling = {
disk = {
capacity_enabled : true,
diff --git a/examples/pitr/main.tf b/examples/pitr/main.tf
index adbdac59..5049517f 100644
--- a/examples/pitr/main.tf
+++ b/examples/pitr/main.tf
@@ -16,17 +16,18 @@ module "postgresql_db_pitr" {
# remove the above line and uncomment the below 2 lines to consume the module from the registry
# source = "terraform-ibm-modules/icd-postgresql/ibm"
# version = "X.Y.Z" # Replace "X.Y.Z" with a release version to lock into a specific release
- resource_group_id = module.resource_group.resource_group_id
- name = "${var.prefix}-postgres-pitr"
- region = var.region
- tags = var.resource_tags
- access_tags = var.access_tags
- memory_mb = 4096
- disk_mb = 5120
- cpu_count = 0
- member_host_flavor = "multitenant"
- members = var.members
- postgresql_version = var.postgresql_version
- pitr_id = var.pitr_id
- pitr_time = var.pitr_time
+ resource_group_id = module.resource_group.resource_group_id
+ name = "${var.prefix}-postgres-pitr"
+ region = var.region
+ tags = var.resource_tags
+ access_tags = var.access_tags
+ memory_mb = 4096
+ disk_mb = 5120
+ cpu_count = 0
+ deletion_protection = false
+ member_host_flavor = "multitenant"
+ members = var.members
+ postgresql_version = var.postgresql_version
+ pitr_id = var.pitr_id
+ pitr_time = var.pitr_time
}
diff --git a/ibm_catalog.json b/ibm_catalog.json
index fc3487a2..03a6db74 100644
--- a/ibm_catalog.json
+++ b/ibm_catalog.json
@@ -290,6 +290,15 @@
}
]
},
+ {
+ "key": "deletion_protection"
+ },
+ {
+ "key": "timeouts_update"
+ },
+ {
+ "key": "version_upgrade_skip_backup"
+ },
{
"key": "service_credential_names"
},
@@ -564,6 +573,12 @@
{
"key": "configuration"
},
+ {
+ "key": "deletion_protection"
+ },
+ {
+ "key": "timeouts_update"
+ },
{
"key": "service_credential_names"
},
diff --git a/main.tf b/main.tf
index baad9743..cb84334b 100644
--- a/main.tf
+++ b/main.tf
@@ -171,6 +171,8 @@ resource "ibm_database" "postgresql_db" {
version = var.postgresql_version
resource_group_id = var.resource_group_id
service_endpoints = var.service_endpoints
+ deletion_protection = var.deletion_protection
+ version_upgrade_skip_backup = var.version_upgrade_skip_backup
tags = var.tags
adminpassword = var.admin_pass
key_protect_key = var.kms_key_crn
@@ -297,7 +299,6 @@ resource "ibm_database" "postgresql_db" {
lifecycle {
ignore_changes = [
# Ignore changes to these because a change will destroy and recreate the instance
- version,
key_protect_key,
backup_encryption_key_crn,
]
@@ -305,7 +306,7 @@ resource "ibm_database" "postgresql_db" {
timeouts {
create = "120m" # Extending provisioning time to 120 minutes
- update = "120m"
+ update = var.timeouts_update
delete = "15m"
}
}
diff --git a/modules/fscloud/README.md b/modules/fscloud/README.md
index 9e9c9f71..fafbe363 100644
--- a/modules/fscloud/README.md
+++ b/modules/fscloud/README.md
@@ -35,6 +35,7 @@ No resources.
| [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 |
| [cbr\_rules](#input\_cbr\_rules) | (Optional, list) List of CBR rules to create | list(object({
description = string
account_id = string
rule_contexts = list(object({
attributes = optional(list(object({
name = string
value = string
}))) }))
enforcement_mode = string
tags = optional(list(object({
name = string
value = string
})))
operations = optional(list(object({
api_types = list(object({
api_type_id = string
}))
})))
})) | `[]` | no |
| [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. | object({
shared_buffers = optional(number)
max_connections = optional(number)
# below field gives error when sent to provider
# tracking issue: https://github.com/IBM-Cloud/terraform-provider-ibm/issues/5403
# max_locks_per_transaction = optional(number)
max_prepared_transactions = optional(number)
synchronous_commit = optional(string)
effective_io_concurrency = optional(number)
deadlock_timeout = optional(number)
log_connections = optional(string)
log_disconnections = optional(string)
log_min_duration_statement = optional(number)
tcp_keepalives_idle = optional(number)
tcp_keepalives_interval = optional(number)
tcp_keepalives_count = optional(number)
archive_timeout = optional(number)
wal_level = optional(string)
max_replication_slots = optional(number)
max_wal_senders = optional(number)
}) | `null` | no |
+| [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 |
| [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 |
| [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-postgresql?topic=databases-for-postgresql-resources-scaling) | `number` | `3` | no |
| [member\_disk\_mb](#input\_member\_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 |
@@ -49,10 +50,12 @@ No resources.
| [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 |
| [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 |
| [tags](#input\_tags) | Optional list of tags to be added to the PostgreSQL instance. | `list(string)` | `[]` | no |
+| [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 |
| [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 |
| [use\_ibm\_owned\_encryption\_key](#input\_use\_ibm\_owned\_encryption\_key) | Set to true to use the default IBM Cloud® Databases randomly generated keys for disk and backups encryption. To control the encryption keys, use the `kms_key_crn` and `backup_encryption_key_crn` inputs. | `string` | `false` | no |
| [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 |
| [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 | list(object({
name = string
password = string # pragma: allowlist secret
type = optional(string)
role = optional(string)
})) | `[]` | no |
+| [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 |
### Outputs
diff --git a/modules/fscloud/main.tf b/modules/fscloud/main.tf
index fd88a682..761e751f 100644
--- a/modules/fscloud/main.tf
+++ b/modules/fscloud/main.tf
@@ -6,6 +6,9 @@ module "postgresql_db" {
remote_leader_crn = var.remote_leader_crn
skip_iam_authorization_policy = var.skip_iam_authorization_policy
service_endpoints = "private"
+ deletion_protection = var.deletion_protection
+ version_upgrade_skip_backup = var.version_upgrade_skip_backup
+ timeouts_update = var.timeouts_update
postgresql_version = var.postgresql_version
use_ibm_owned_encryption_key = var.use_ibm_owned_encryption_key
use_same_kms_key_for_backups = var.use_same_kms_key_for_backups
diff --git a/modules/fscloud/variables.tf b/modules/fscloud/variables.tf
index 5cfc79f8..ed564147 100644
--- a/modules/fscloud/variables.tf
+++ b/modules/fscloud/variables.tf
@@ -95,6 +95,24 @@ variable "access_tags" {
default = []
}
+variable "version_upgrade_skip_backup" {
+ type = bool
+ description = "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."
+ default = false
+}
+
+variable "deletion_protection" {
+ type = bool
+ description = "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'."
+ default = true
+}
+
+variable "timeouts_update" {
+ type = string
+ description = "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)."
+ default = "120m"
+}
+
variable "configuration" {
type = object({
shared_buffers = optional(number)
diff --git a/solutions/fully-configurable/catalogValidationValues.json.template b/solutions/fully-configurable/catalogValidationValues.json.template
index 8114842c..e32ee951 100644
--- a/solutions/fully-configurable/catalogValidationValues.json.template
+++ b/solutions/fully-configurable/catalogValidationValues.json.template
@@ -5,5 +5,6 @@
"name": $PREFIX,
"existing_resource_group_name": "geretain-test-postgres",
"existing_kms_instance_crn": $HPCS_US_SOUTH_CRN,
+ "deletion_protection": false,
"kms_encryption_enabled": true
}
diff --git a/solutions/fully-configurable/main.tf b/solutions/fully-configurable/main.tf
index e9bb1b8a..e505dc63 100644
--- a/solutions/fully-configurable/main.tf
+++ b/solutions/fully-configurable/main.tf
@@ -292,18 +292,21 @@ module "postgresql_db" {
access_tags = var.access_tags
tags = var.resource_tags
# workaround for https://github.com/IBM-Cloud/terraform-provider-ibm/issues/6141
- admin_pass = var.remote_leader_crn == null ? local.admin_pass : null
- users = var.users
- members = var.members
- member_host_flavor = var.member_host_flavor
- memory_mb = var.member_memory_mb
- disk_mb = var.member_disk_mb
- cpu_count = var.member_cpu_count
- auto_scaling = var.auto_scaling
- configuration = var.configuration
- service_credential_names = var.service_credential_names
- backup_crn = var.backup_crn
- service_endpoints = var.service_endpoints
+ admin_pass = var.remote_leader_crn == null ? local.admin_pass : null
+ users = var.users
+ members = var.members
+ member_host_flavor = var.member_host_flavor
+ memory_mb = var.member_memory_mb
+ disk_mb = var.member_disk_mb
+ cpu_count = var.member_cpu_count
+ auto_scaling = var.auto_scaling
+ configuration = var.configuration
+ service_credential_names = var.service_credential_names
+ backup_crn = var.backup_crn
+ service_endpoints = var.service_endpoints
+ deletion_protection = var.deletion_protection
+ version_upgrade_skip_backup = var.version_upgrade_skip_backup
+ timeouts_update = var.timeouts_update
}
locals {
diff --git a/solutions/fully-configurable/variables.tf b/solutions/fully-configurable/variables.tf
index 0850bef1..c261c807 100644
--- a/solutions/fully-configurable/variables.tf
+++ b/solutions/fully-configurable/variables.tf
@@ -203,6 +203,24 @@ variable "access_tags" {
default = []
}
+variable "version_upgrade_skip_backup" {
+ type = bool
+ description = "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."
+ default = false
+}
+
+variable "deletion_protection" {
+ type = bool
+ description = "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'."
+ default = true
+}
+
+variable "timeouts_update" {
+ type = string
+ description = "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)."
+ default = "120m"
+}
+
##############################################################
# Encryption
##############################################################
@@ -244,6 +262,7 @@ variable "kms_endpoint_type" {
type = string
description = "The type of endpoint to use for communicating with the Key Protect or Hyper Protect Crypto Services instance. Possible values: `public`, `private`. Applies only if `existing_kms_key_crn` is not specified."
default = "private"
+
validation {
condition = can(regex("public|private", var.kms_endpoint_type))
error_message = "The kms_endpoint_type value must be 'public' or 'private'."
diff --git a/solutions/security-enforced/catalogValidationValues.json.template b/solutions/security-enforced/catalogValidationValues.json.template
index 710fd8f7..7e333691 100644
--- a/solutions/security-enforced/catalogValidationValues.json.template
+++ b/solutions/security-enforced/catalogValidationValues.json.template
@@ -4,5 +4,6 @@
"resource_tags": $TAGS,
"name": $PREFIX,
"existing_resource_group_name": "geretain-test-postgres",
- "existing_kms_instance_crn": $HPCS_US_SOUTH_CRN
+ "existing_kms_instance_crn": $HPCS_US_SOUTH_CRN,
+ "deletion_protection": false
}
diff --git a/solutions/security-enforced/main.tf b/solutions/security-enforced/main.tf
index c20e6fa2..d5edb3b5 100644
--- a/solutions/security-enforced/main.tf
+++ b/solutions/security-enforced/main.tf
@@ -33,4 +33,7 @@ module "postgresql_db" {
backup_crn = var.backup_crn
auto_scaling = var.auto_scaling
service_endpoints = "private"
+ deletion_protection = var.deletion_protection
+ version_upgrade_skip_backup = false
+ timeouts_update = var.timeouts_update
}
diff --git a/solutions/security-enforced/variables.tf b/solutions/security-enforced/variables.tf
index b74bfd03..eb9a5a72 100644
--- a/solutions/security-enforced/variables.tf
+++ b/solutions/security-enforced/variables.tf
@@ -187,6 +187,18 @@ variable "access_tags" {
default = []
}
+variable "deletion_protection" {
+ type = bool
+ description = "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'."
+ default = true
+}
+
+variable "timeouts_update" {
+ type = string
+ description = "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)."
+ default = "120m"
+}
+
##############################################################
# Encryption
##############################################################
@@ -202,7 +214,6 @@ variable "existing_kms_key_crn" {
description = "The CRN of a Key Protect or Hyper Protect Crypto Services encryption key to encrypt your data. By default this key is used for both deployment data and backups, but this behaviour can be altered using the optional `existing_backup_kms_key_crn` input. If no value is passed a new key will be created in the instance specified in the `existing_kms_instance_crn` input. 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)."
default = null
-
validation {
condition = (
(var.existing_kms_key_crn != null && var.existing_kms_instance_crn == null) ||
diff --git a/tests/pr_test.go b/tests/pr_test.go
index 4ab9fde0..3cfd9275 100644
--- a/tests/pr_test.go
+++ b/tests/pr_test.go
@@ -23,9 +23,9 @@ import (
"github.com/terraform-ibm-modules/ibmcloud-terratest-wrapper/testschematic"
)
+const fscloudExampleTerraformDir = "examples/fscloud"
const fullyConfigurableSolutionTerraformDir = "solutions/fully-configurable"
const securityEnforcedSolutionTerraformDir = "solutions/security-enforced"
-const fscloudExampleTerraformDir = "examples/fscloud"
const latestVersion = "17"
// Use existing resource group
@@ -83,6 +83,7 @@ func TestRunFullyConfigurableSolutionSchematics(t *testing.T) {
{Name: "ibmcloud_api_key", Value: options.RequiredEnvironmentVars["TF_VAR_ibmcloud_api_key"], DataType: "string", Secure: true},
{Name: "access_tags", Value: permanentResources["accessTags"], DataType: "list(string)"},
{Name: "kms_encryption_enabled", Value: true, DataType: "bool"},
+ {Name: "deletion_protection", Value: false, DataType: "bool"},
{Name: "existing_kms_instance_crn", Value: permanentResources["hpcs_south_crn"], DataType: "string"},
{Name: "existing_backup_kms_key_crn", Value: permanentResources["hpcs_south_root_key_crn"], DataType: "string"},
{Name: "kms_endpoint_type", Value: "private", DataType: "string"},
@@ -119,6 +120,7 @@ func TestRunSecurityEnforcedSolutionSchematics(t *testing.T) {
{Name: "prefix", Value: options.Prefix, DataType: "string", Secure: true},
{Name: "ibmcloud_api_key", Value: options.RequiredEnvironmentVars["TF_VAR_ibmcloud_api_key"], DataType: "string", Secure: true},
{Name: "access_tags", Value: permanentResources["accessTags"], DataType: "list(string)"},
+ {Name: "deletion_protection", Value: false, DataType: "bool"},
{Name: "existing_kms_instance_crn", Value: permanentResources["hpcs_south_crn"], DataType: "string"},
{Name: "existing_backup_kms_key_crn", Value: permanentResources["hpcs_south_root_key_crn"], DataType: "string"},
{Name: "postgresql_version", Value: "16", DataType: "string"}, // Always lock this test into the latest supported PostgresSQL version
@@ -152,6 +154,7 @@ func TestRunSecurityEnforcedUpgradeSolutionSchematics(t *testing.T) {
options.TerraformVars = []testschematic.TestSchematicTerraformVar{
{Name: "ibmcloud_api_key", Value: options.RequiredEnvironmentVars["TF_VAR_ibmcloud_api_key"], DataType: "string", Secure: true},
{Name: "prefix", Value: options.Prefix, DataType: "string"},
+ {Name: "deletion_protection", Value: false, DataType: "bool"},
{Name: "existing_resource_group_name", Value: resourceGroup, DataType: "string"},
{Name: "existing_kms_instance_crn", Value: permanentResources["hpcs_south_crn"], DataType: "string"},
}
@@ -291,6 +294,7 @@ func TestRunExistingInstance(t *testing.T) {
{Name: "ibmcloud_api_key", Value: options.RequiredEnvironmentVars["TF_VAR_ibmcloud_api_key"], DataType: "string", Secure: true},
{Name: "existing_postgresql_instance_crn", Value: terraform.Output(t, existingTerraformOptions, "postgresql_crn"), DataType: "string"},
{Name: "existing_resource_group_name", Value: resourceGroup, DataType: "string"},
+ {Name: "deletion_protection", Value: false, DataType: "bool"},
{Name: "region", Value: region, DataType: "string"},
{Name: "provider_visibility", Value: "public", DataType: "string"},
}
diff --git a/variables.tf b/variables.tf
index 0df7a3d7..9f90abeb 100644
--- a/variables.tf
+++ b/variables.tf
@@ -141,6 +141,24 @@ variable "access_tags" {
}
}
+variable "version_upgrade_skip_backup" {
+ type = bool
+ description = "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."
+ default = false
+}
+
+variable "deletion_protection" {
+ type = bool
+ description = "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'."
+ default = true
+}
+
+variable "timeouts_update" {
+ type = string
+ description = "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)."
+ default = "120m"
+}
+
variable "configuration" {
type = object({
shared_buffers = optional(number)