Skip to content

Commit 658f852

Browse files
authored
fix: fixed bug with logic that produced and error when passing a value for admin password (#568)
1 parent 293a637 commit 658f852

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

solutions/standard/main.tf

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,7 @@ locals {
234234
# if - replace first char with J
235235
# elseif _ replace first char with K
236236
# else use asis
237-
generated_admin_password = startswith(random_password.admin_password[0].result, "-") ? "J${substr(random_password.admin_password[0].result, 1, -1)}" : startswith(random_password.admin_password[0].result, "_") ? "K${substr(random_password.admin_password[0].result, 1, -1)}" : random_password.admin_password[0].result
238-
239-
# admin password to use
240-
admin_pass = var.admin_pass == null ? local.generated_admin_password : var.admin_pass
237+
admin_pass = var.admin_pass == null ? (startswith(random_password.admin_password[0].result, "-") ? "J${substr(random_password.admin_password[0].result, 1, -1)}" : startswith(random_password.admin_password[0].result, "_") ? "K${substr(random_password.admin_password[0].result, 1, -1)}" : random_password.admin_password[0].result) : var.admin_pass
241238
}
242239

243240
#######################################################################################################################

tests/pr_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22
package test
33

44
import (
5+
"crypto/rand"
6+
"encoding/base64"
57
"log"
68
"os"
79
"testing"
810

911
"github.com/gruntwork-io/terratest/modules/terraform"
1012
"github.com/stretchr/testify/assert"
13+
"github.com/stretchr/testify/require"
1114
"github.com/terraform-ibm-modules/ibmcloud-terratest-wrapper/cloudinfo"
1215
"github.com/terraform-ibm-modules/ibmcloud-terratest-wrapper/common"
1316
"github.com/terraform-ibm-modules/ibmcloud-terratest-wrapper/testhelper"
@@ -148,6 +151,13 @@ func TestRunStandardSolutionIBMKeys(t *testing.T) {
148151
func TestRunStandardUpgradeSolution(t *testing.T) {
149152
t.Parallel()
150153

154+
// Generate a 15 char long random string for the admin_pass.
155+
randomBytes := make([]byte, 13)
156+
_, randErr := rand.Read(randomBytes)
157+
require.Nil(t, randErr) // do not proceed if we can't gen a random password
158+
159+
randomPass := "A1" + base64.URLEncoding.EncodeToString(randomBytes)[:13]
160+
151161
options := testhelper.TestOptionsDefault(&testhelper.TestOptions{
152162
Testing: t,
153163
TerraformDir: standardSolutionTerraformDir,
@@ -161,6 +171,7 @@ func TestRunStandardUpgradeSolution(t *testing.T) {
161171
"kms_endpoint_type": "public",
162172
"provider_visibility": "public",
163173
"resource_group_name": options.Prefix,
174+
"admin_pass": randomPass,
164175
}
165176

166177
output, err := options.RunTestUpgrade()

0 commit comments

Comments
 (0)