Skip to content

Commit b152965

Browse files
authored
fix: remove null optional elements before jsonencode is called (resolves this [bug](#273) (#284)
1 parent 30af89a commit b152965

File tree

4 files changed

+23
-18
lines changed

4 files changed

+23
-18
lines changed

examples/complete/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ An end-to-end example that does the following:
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 BYOK encryption.
8+
- Set 250 max connection for ICD PostgreSQL database instance.
89
- Create service credentials for the database instance.
910
- Create a Virtual Private Cloud (VPC).
1011
- Create Context Based Restriction (CBR) to only allow Postgresql to be accessible from the VPC.

examples/complete/main.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ module "postgresql_db" {
8383
resource_tags = var.resource_tags
8484
service_credential_names = var.service_credential_names
8585
access_tags = var.access_tags
86+
configuration = {
87+
max_connections = 250
88+
}
8689
cbr_rules = [
8790
{
8891
description = "${var.prefix}-postgres access only from vpc"

main.tf

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,21 @@ resource "time_sleep" "wait_for_authorization_policy" {
4848

4949
# Create postgresql database
5050
resource "ibm_database" "postgresql_db" {
51-
depends_on = [ibm_iam_authorization_policy.kms_policy]
52-
resource_group_id = var.resource_group_id
53-
name = var.name
54-
service = "databases-for-postgresql"
55-
location = var.region
56-
plan = "standard" # Only standard plan is available for postgres
57-
backup_id = var.backup_crn
58-
plan_validation = var.plan_validation
59-
remote_leader_id = var.remote_leader_crn
60-
version = var.pg_version
61-
tags = var.resource_tags
62-
adminpassword = var.admin_pass
63-
service_endpoints = var.service_endpoints
64-
configuration = var.configuration != null ? jsonencode(var.configuration) : null
51+
depends_on = [ibm_iam_authorization_policy.kms_policy]
52+
resource_group_id = var.resource_group_id
53+
name = var.name
54+
service = "databases-for-postgresql"
55+
location = var.region
56+
plan = "standard" # Only standard plan is available for postgres
57+
backup_id = var.backup_crn
58+
plan_validation = var.plan_validation
59+
remote_leader_id = var.remote_leader_crn
60+
version = var.pg_version
61+
tags = var.resource_tags
62+
adminpassword = var.admin_pass
63+
service_endpoints = var.service_endpoints
64+
# remove elements with null values: see https://github.com/terraform-ibm-modules/terraform-ibm-icd-postgresql/issues/273
65+
configuration = var.configuration != null ? jsonencode({ for k, v in var.configuration : k => v if v != null }) : null
6566
key_protect_key = var.kms_key_crn
6667
backup_encryption_key_crn = local.backup_encryption_key_crn
6768
point_in_time_recovery_deployment_id = var.pitr_id

module-metadata.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@
523523
},
524524
"pos": {
525525
"filename": "main.tf",
526-
"line": 190
526+
"line": 191
527527
}
528528
},
529529
"ibm_resource_tag.postgresql_tag": {
@@ -539,7 +539,7 @@
539539
},
540540
"pos": {
541541
"filename": "main.tf",
542-
"line": 141
542+
"line": 142
543543
}
544544
},
545545
"time_sleep.wait_for_authorization_policy": {
@@ -571,7 +571,7 @@
571571
},
572572
"pos": {
573573
"filename": "main.tf",
574-
"line": 218
574+
"line": 219
575575
}
576576
}
577577
},
@@ -650,7 +650,7 @@
650650
},
651651
"pos": {
652652
"filename": "main.tf",
653-
"line": 151
653+
"line": 152
654654
}
655655
}
656656
}

0 commit comments

Comments
 (0)