Skip to content

Commit 7be0573

Browse files
authored
fix: remove null optional elements before jsonencode is called (resolves this [bug](terraform-ibm-modules/terraform-ibm-icd-postgresql#273) (#223)
1 parent a4b0d66 commit 7be0573

File tree

4 files changed

+21
-16
lines changed

4 files changed

+21
-16
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 uses the IBM Cloud Terraform provider to create the f
55
- A resource group, if one is not passed in.
66
- A Key Protect instance with a root key.
77
- An instance of Databases for MongoDB with BYOK encryption.
8+
- Set 250 max connection for Databases for MongoDB instance.
89
- Service credentials for the database instance.
910
- A sample virtual private cloud (VPC).
1011
- A context-based restriction (CBR) rule to only allow MongoDB to be accessible from within 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 "mongodb" {
8383
access_tags = var.access_tags
8484
tags = var.resource_tags
8585
service_credential_names = var.service_credential_names
86+
configuration = {
87+
max_connections = 250
88+
}
8689
cbr_rules = [
8790
{
8891
description = "${var.prefix}-mongodb access only from vpc"

main.tf

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,19 @@ resource "time_sleep" "wait_for_authorization_policy" {
4545
}
4646

4747
resource "ibm_database" "mongodb" {
48-
depends_on = [ibm_iam_authorization_policy.kms_policy]
49-
name = var.instance_name
50-
location = var.region
51-
plan = var.plan
52-
service = "databases-for-mongodb"
53-
version = var.mongodb_version
54-
resource_group_id = var.resource_group_id
55-
adminpassword = var.admin_pass
56-
tags = var.tags
57-
service_endpoints = var.endpoints
58-
plan_validation = var.plan_validation
59-
configuration = var.configuration != null ? jsonencode(var.configuration) : null
48+
depends_on = [ibm_iam_authorization_policy.kms_policy]
49+
name = var.instance_name
50+
location = var.region
51+
plan = var.plan
52+
service = "databases-for-mongodb"
53+
version = var.mongodb_version
54+
resource_group_id = var.resource_group_id
55+
adminpassword = var.admin_pass
56+
tags = var.tags
57+
service_endpoints = var.endpoints
58+
plan_validation = var.plan_validation
59+
# remove elements with null values: see https://github.com/terraform-ibm-modules/terraform-ibm-icd-postgresql/issues/273
60+
configuration = var.configuration != null ? jsonencode({ for k, v in var.configuration : k => v if v != null }) : null
6061
key_protect_key = var.kms_key_crn
6162
backup_encryption_key_crn = local.backup_encryption_key_crn
6263

module-metadata.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@
481481
},
482482
"pos": {
483483
"filename": "main.tf",
484-
"line": 182
484+
"line": 183
485485
}
486486
},
487487
"ibm_resource_tag.mongodb_tag": {
@@ -497,7 +497,7 @@
497497
},
498498
"pos": {
499499
"filename": "main.tf",
500-
"line": 131
500+
"line": 132
501501
}
502502
},
503503
"time_sleep.wait_for_authorization_policy": {
@@ -529,7 +529,7 @@
529529
},
530530
"pos": {
531531
"filename": "main.tf",
532-
"line": 210
532+
"line": 211
533533
}
534534
}
535535
},
@@ -608,7 +608,7 @@
608608
},
609609
"pos": {
610610
"filename": "main.tf",
611-
"line": 142
611+
"line": 143
612612
}
613613
}
614614
}

0 commit comments

Comments
 (0)