Skip to content

Commit 791d46d

Browse files
aatreyee2506Aatreyee Mukherjee
andauthored
feat: Module updates:<br> - resource_tags input variable renamed to tags<br> - cbr_rules has been extended to support tags and operations<br> * DA updates: <br> - Added support for passing existing Postgresql instance <br> - Added a new input variable existing_postgresql_instance_crn (#596)
* test-coverage:postgresql * fix:upgrade-test * added variables in catalog.json * fixed:pre-commit --------- Co-authored-by: Aatreyee Mukherjee <aatreyeemukherjee@Aatreyees-MacBook-Pro.local>
1 parent d4a1f4b commit 791d46d

File tree

22 files changed

+276
-209
lines changed

22 files changed

+276
-209
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ To attach access management tags to resources in this module, you need the follo
9898
| <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 |
9999
| <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 |
100100
| <a name="input_backup_encryption_key_crn"></a> [backup\_encryption\_key\_crn](#input\_backup\_encryption\_key\_crn) | The CRN of a Key Protect or Hyper Protect Crypto Services encryption key that you want to use for encrypting the disk that holds deployment backups. Applies only if `use_ibm_owned_encryption_key` is false and `use_same_kms_key_for_backups` is false. If no value is passed, and `use_same_kms_key_for_backups` is true, the value of `kms_key_crn` is used. Alternatively set `use_default_backup_encryption_key` to true to use the IBM Cloud Databases default encryption. Bare in mind that backups encryption is only available in certain regions. See [Bring your own key for backups](https://cloud.ibm.com/docs/cloud-databases?topic=cloud-databases-key-protect&interface=ui#key-byok) and [Using the HPCS Key for Backup encryption](https://cloud.ibm.com/docs/cloud-databases?topic=cloud-databases-hpcs#use-hpcs-backups). | `string` | `null` | no |
101-
| <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 |
101+
| <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_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 |
104104
| <a name="input_member_cpu_count"></a> [member\_cpu\_count](#input\_member\_cpu\_count) | Allocated dedicated CPU per member. For shared CPU, set to 0. [Learn more](https://cloud.ibm.com/docs/databases-for-postgresql?topic=databases-for-postgresql-resources-scaling). Ignored during restore and point in time recovery operations | `number` | `0` | no |
@@ -113,10 +113,10 @@ To attach access management tags to resources in this module, you need the follo
113113
| <a name="input_region"></a> [region](#input\_region) | The region where you want to deploy your instance. | `string` | `"us-south"` | no |
114114
| <a name="input_remote_leader_crn"></a> [remote\_leader\_crn](#input\_remote\_leader\_crn) | A CRN of the leader database to make the replica(read-only) deployment. The leader database is created by a database deployment with the same service ID. A read-only replica is set up to replicate all of your data from the leader deployment to the replica deployment by using asynchronous replication. For more information, see https://cloud.ibm.com/docs/databases-for-postgresql?topic=databases-for-postgresql-read-only-replicas | `string` | `null` | no |
115115
| <a name="input_resource_group_id"></a> [resource\_group\_id](#input\_resource\_group\_id) | The resource group ID where the PostgreSQL instance will be created. | `string` | n/a | yes |
116-
| <a name="input_resource_tags"></a> [resource\_tags](#input\_resource\_tags) | Optional list of tags to be added to the PostgreSQL instance. | `list(string)` | `[]` | no |
117116
| <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 |
118117
| <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 |
119118
| <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 |
119+
| <a name="input_tags"></a> [tags](#input\_tags) | Optional list of tags to be added to the PostgreSQL instance. | `list(string)` | `[]` | no |
120120
| <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 |
121121
| <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 |
122122
| <a name="input_use_same_kms_key_for_backups"></a> [use\_same\_kms\_key\_for\_backups](#input\_use\_same\_kms\_key\_for\_backups) | Set this to false if you wan't to use a different key that you own to encrypt backups. When set to false, a value is required for the `backup_encryption_key_crn` input. Alternatiely set `use_default_backup_encryption_key` to true to use the IBM Cloud Databases default encryption. Applies only if `use_ibm_owned_encryption_key` is false. Bare in mind that backups encryption is only available in certain regions. See [Bring your own key for backups](https://cloud.ibm.com/docs/cloud-databases?topic=cloud-databases-key-protect&interface=ui#key-byok) and [Using the HPCS Key for Backup encryption](https://cloud.ibm.com/docs/cloud-databases?topic=cloud-databases-hpcs#use-hpcs-backups). | `bool` | `true` | no |

examples/backup/main.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module "postgresql_db" {
1717
name = "${var.prefix}-postgres"
1818
pg_version = var.pg_version
1919
region = var.region
20-
resource_tags = var.resource_tags
20+
tags = var.resource_tags
2121
access_tags = var.access_tags
2222
member_host_flavor = "multitenant"
2323
}
@@ -28,13 +28,13 @@ data "ibm_database_backups" "backup_database" {
2828
}
2929

3030
# New postgresql instance pointing to the backup instance
31-
module "restored_postgresql_db" {
31+
module "restored_icd_postgresql" {
3232
source = "../.."
3333
resource_group_id = module.resource_group.resource_group_id
3434
name = "${var.prefix}-postgres-restored"
3535
pg_version = var.pg_version
3636
region = var.region
37-
resource_tags = var.resource_tags
37+
tags = var.resource_tags
3838
access_tags = var.access_tags
3939
member_host_flavor = "multitenant"
4040
backup_crn = var.postgresql_db_backup_crn == null ? data.ibm_database_backups.backup_database[0].backups[0].backup_id : var.postgresql_db_backup_crn

examples/backup/outputs.tf

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
##############################################################################
22
# Outputs
33
##############################################################################
4-
output "id" {
5-
description = "Postgresql instance id"
6-
value = var.postgresql_db_backup_crn == null ? module.postgresql_db[0].id : null
7-
}
8-
9-
output "restored_postgresql_db_id" {
4+
output "restored_icd_postgresql_id" {
105
description = "Restored Postgresql instance id"
11-
value = module.restored_postgresql_db.id
6+
value = module.restored_icd_postgresql.id
127
}
138

14-
output "restored_postgresql_db_version" {
9+
output "restored_icd_postgresql_version" {
1510
description = "Restored Postgresql instance version"
16-
value = module.restored_postgresql_db.version
11+
value = module.restored_icd_postgresql.version
1712
}

examples/basic/main.tf

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,25 @@ module "resource_group" {
1111
}
1212

1313
##############################################################################
14-
# ICD postgresql database
14+
# Postgresql
1515
##############################################################################
1616

17-
module "postgresql_db" {
17+
module "database" {
1818
source = "../.."
1919
resource_group_id = module.resource_group.resource_group_id
20-
name = "${var.prefix}-postgres"
20+
name = "${var.prefix}-data-store"
2121
pg_version = var.pg_version
2222
region = var.region
23-
resource_tags = var.resource_tags
23+
tags = var.resource_tags
2424
access_tags = var.access_tags
25+
service_endpoints = var.service_endpoints
2526
member_host_flavor = var.member_host_flavor
27+
service_credential_names = {
28+
"postgresql_admin" : "Administrator",
29+
"postgresql_operator" : "Operator",
30+
"postgresql_viewer" : "Viewer",
31+
"postgresql_editor" : "Editor",
32+
}
2633
}
2734

2835
# On destroy, we are seeing that even though the replica has been returned as
@@ -34,7 +41,7 @@ module "postgresql_db" {
3441
# adding a time sleep here.
3542

3643
resource "time_sleep" "wait_time" {
37-
depends_on = [module.postgresql_db]
44+
depends_on = [module.database]
3845

3946
destroy_duration = "5m"
4047
}
@@ -49,10 +56,10 @@ module "read_only_replica_postgresql_db" {
4956
resource_group_id = module.resource_group.resource_group_id
5057
name = "${var.prefix}-read-only-replica-${count.index}"
5158
region = var.region
52-
resource_tags = var.resource_tags
59+
tags = var.resource_tags
5360
access_tags = var.access_tags
5461
pg_version = var.pg_version
55-
remote_leader_crn = module.postgresql_db.crn
62+
remote_leader_crn = module.database.crn
5663
member_host_flavor = "multitenant"
5764
member_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.
5865
member_disk_mb = 5120 # Must be an increment of 512 megabytes. The minimum size of a read-only replica is 5 GB of disk

examples/basic/outputs.tf

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,36 @@
33
##############################################################################
44
output "id" {
55
description = "Postgresql instance id"
6-
value = module.postgresql_db.id
6+
value = module.database.id
77
}
88

99
output "version" {
1010
description = "Postgresql instance version"
11-
value = module.postgresql_db.version
11+
value = module.database.version
1212
}
1313

1414
output "adminuser" {
1515
description = "Database admin user name"
16-
value = module.postgresql_db.adminuser
16+
value = module.database.adminuser
1717
}
1818

1919
output "hostname" {
2020
description = "Database connection hostname"
21-
value = module.postgresql_db.hostname
21+
value = module.database.hostname
2222
}
2323

2424
output "port" {
2525
description = "Database connection port"
26-
value = module.postgresql_db.port
26+
value = module.database.port
2727
}
2828

2929
output "certificate_base64" {
3030
description = "Database connection certificate"
31-
value = module.postgresql_db.certificate_base64
31+
value = module.database.certificate_base64
3232
sensitive = true
3333
}
34+
35+
output "postgresql_crn" {
36+
description = "Postgresql CRN"
37+
value = module.database.crn
38+
}

examples/basic/variables.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,14 @@ variable "member_host_flavor" {
5656
description = "Allocated host flavor per member. For more information, see https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/database#host_flavor"
5757
default = null
5858
}
59+
60+
variable "service_endpoints" {
61+
type = string
62+
description = "The type of endpoint of the database instance. Possible values: `public`, `private`, `public-and-private`."
63+
default = "public"
64+
65+
validation {
66+
condition = can(regex("public|public-and-private|private", var.service_endpoints))
67+
error_message = "Valid values for service_endpoints are 'public', 'public-and-private', and 'private'"
68+
}
69+
}

examples/complete/main.tf

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ module "key_protect_all_inclusive" {
3030
resource_tags = var.resource_tags
3131
keys = [
3232
{
33-
key_ring_name = "icd-pg"
33+
key_ring_name = "icd"
3434
keys = [
3535
{
3636
key_name = local.data_key_name
@@ -101,7 +101,7 @@ module "cbr_zone" {
101101
# Postgres Instance
102102
##############################################################################
103103

104-
module "postgresql_db" {
104+
module "icd_postgresql" {
105105
source = "../../"
106106
resource_group_id = module.resource_group.resource_group_id
107107
name = "${var.prefix}-postgres"
@@ -112,9 +112,9 @@ module "postgresql_db" {
112112
# Example of how to use different KMS keys for data and backups
113113
use_ibm_owned_encryption_key = false
114114
use_same_kms_key_for_backups = false
115-
kms_key_crn = module.key_protect_all_inclusive.keys["icd-pg.${local.data_key_name}"].crn
116-
backup_encryption_key_crn = module.key_protect_all_inclusive.keys["icd-pg.${local.backups_key_name}"].crn
117-
resource_tags = var.resource_tags
115+
kms_key_crn = module.key_protect_all_inclusive.keys["icd.${local.data_key_name}"].crn
116+
backup_encryption_key_crn = module.key_protect_all_inclusive.keys["icd.${local.backups_key_name}"].crn
117+
tags = var.resource_tags
118118
service_credential_names = {
119119
"postgressql_admin" : "Administrator",
120120
"postgressql_operator" : "Operator",
@@ -164,7 +164,7 @@ module "postgresql_db" {
164164

165165
# VPE provisioning should wait for the database provisioning
166166
resource "time_sleep" "wait_120_seconds" {
167-
depends_on = [module.postgresql_db]
167+
depends_on = [module.icd_postgresql]
168168
create_duration = "120s"
169169
}
170170

@@ -179,7 +179,7 @@ module "vpe" {
179179
cloud_service_by_crn = [
180180
{
181181
service_name = "${var.prefix}-postgres"
182-
crn = module.postgresql_db.crn
182+
crn = module.icd_postgresql.crn
183183
},
184184
]
185185
vpc_id = module.vpc.vpc_id

examples/complete/outputs.tf

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,42 @@
33
##############################################################################
44
output "id" {
55
description = "Postgresql instance id"
6-
value = module.postgresql_db.id
6+
value = module.icd_postgresql.id
77
}
88

99
output "guid" {
1010
description = "Postgresql instance guid"
11-
value = module.postgresql_db.guid
11+
value = module.icd_postgresql.guid
1212
}
1313

1414
output "version" {
1515
description = "Postgresql instance version"
16-
value = module.postgresql_db.version
16+
value = module.icd_postgresql.version
1717
}
1818

1919
output "service_credentials_json" {
2020
description = "Service credentials json map"
21-
value = module.postgresql_db.service_credentials_json
21+
value = module.icd_postgresql.service_credentials_json
2222
sensitive = true
2323
}
2424

2525
output "service_credentials_object" {
2626
description = "Service credentials object"
27-
value = module.postgresql_db.service_credentials_object
27+
value = module.icd_postgresql.service_credentials_object
2828
sensitive = true
2929
}
3030

3131
output "cbr_rule_ids" {
3232
description = "CBR rule ids created to restrict Postgresql"
33-
value = module.postgresql_db.cbr_rule_ids
33+
value = module.icd_postgresql.cbr_rule_ids
3434
}
3535

3636
output "hostname" {
3737
description = "Postgresql instance hostname"
38-
value = module.postgresql_db.hostname
38+
value = module.icd_postgresql.hostname
3939
}
4040

4141
output "port" {
4242
description = "Postgresql instance port"
43-
value = module.postgresql_db.port
43+
value = module.icd_postgresql.port
4444
}

0 commit comments

Comments
 (0)