Skip to content

Commit 797bc62

Browse files
authored
fix: fix output error for hostname and port and bug that was preventing service credentials from being created in fscloud profile submodule (#210)
1 parent f592742 commit 797bc62

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

examples/fscloud/outputs.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,13 @@ output "version" {
1515
description = "MongoDB instance version"
1616
value = module.mongodb.version
1717
}
18+
19+
output "hostname" {
20+
description = "Database hostname. Only contains value when var.service_credential_names or var.users are set."
21+
value = module.mongodb.hostname
22+
}
23+
24+
output "port" {
25+
description = "Database port. Only contains value when var.service_credential_names or var.users are set."
26+
value = module.mongodb.port
27+
}

outputs.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ output "service_credentials_object" {
4141

4242
output "hostname" {
4343
description = "Database hostname. Only contains value when var.service_credential_names or var.users are set."
44-
value = length(var.service_credential_names) > 0 ? nonsensitive(ibm_resource_key.service_credentials[keys(var.service_credential_names)[0]].credentials["connection.mongodb.hosts.0.hostname"]) : length(var.users) > 0 ? nonsensitive(flatten(data.ibm_database_connection.database_connection[0].mongodb[0].hosts[0].hostname)) : null
44+
value = length(var.service_credential_names) > 0 ? nonsensitive(ibm_resource_key.service_credentials[keys(var.service_credential_names)[0]].credentials["connection.mongodb.hosts.0.hostname"]) : length(var.users) > 0 ? data.ibm_database_connection.database_connection[0].mongodb[0].hosts[0].hostname : null
4545
}
4646

4747
output "port" {
4848
description = "Database port. Only contains value when var.service_credential_names or var.users are set."
49-
value = length(var.service_credential_names) > 0 ? nonsensitive(ibm_resource_key.service_credentials[keys(var.service_credential_names)[0]].credentials["connection.mongodb.hosts.0.port"]) : length(var.users) > 0 ? nonsensitive(flatten(data.ibm_database_connection.database_connection[0].mongodb[0].hosts[0].port)) : null
49+
value = length(var.service_credential_names) > 0 ? nonsensitive(ibm_resource_key.service_credentials[keys(var.service_credential_names)[0]].credentials["connection.mongodb.hosts.0.port"]) : length(var.users) > 0 ? data.ibm_database_connection.database_connection[0].mongodb[0].hosts[0].port : null
5050
}

profiles/fscloud/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ module "mongodb" {
2222
disk_mb = var.disk_mb
2323
cpu_count = var.cpu_count
2424
auto_scaling = var.auto_scaling
25+
service_credential_names = var.service_credential_names
2526
}

tests/pr_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"os"
99
"testing"
1010

11+
"github.com/gruntwork-io/terratest/modules/terraform"
1112
"github.com/stretchr/testify/assert"
1213
"github.com/terraform-ibm-modules/ibmcloud-terratest-wrapper/common"
1314
"github.com/terraform-ibm-modules/ibmcloud-terratest-wrapper/testhelper"
@@ -57,9 +58,17 @@ func TestRunFSCloudExample(t *testing.T) {
5758
"mongodb_version": "5.0", // Always lock this test into the latest supported MongoDB version
5859
},
5960
})
61+
options.SkipTestTearDown = true
6062
output, err := options.RunTestConsistency()
6163
assert.Nil(t, err, "This should not have errored")
6264
assert.NotNil(t, output, "Expected some output")
65+
66+
// check if outputs exist
67+
outputs := terraform.OutputAll(options.Testing, options.TerraformOptions)
68+
expectedOutputs := []string{"port", "hostname"}
69+
_, outputErr := testhelper.ValidateTerraformOutputs(outputs, expectedOutputs...)
70+
assert.NoErrorf(t, outputErr, "Some outputs not found or nil")
71+
options.TestTearDown()
6372
}
6473

6574
func TestRunCompleteUpgradeExample(t *testing.T) {

0 commit comments

Comments
 (0)