Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions solutions/standard/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,7 @@ locals {
# if - replace first char with J
# elseif _ replace first char with K
# else use asis
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

# admin password to use
admin_pass = var.admin_pass == null ? local.generated_admin_password : var.admin_pass
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
}

#######################################################################################################################
Expand Down
11 changes: 11 additions & 0 deletions tests/pr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
package test

import (
"crypto/rand"
"encoding/base64"
"log"
"os"
"testing"

"github.com/gruntwork-io/terratest/modules/terraform"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/terraform-ibm-modules/ibmcloud-terratest-wrapper/cloudinfo"
"github.com/terraform-ibm-modules/ibmcloud-terratest-wrapper/common"
"github.com/terraform-ibm-modules/ibmcloud-terratest-wrapper/testhelper"
Expand Down Expand Up @@ -148,6 +151,13 @@ func TestRunStandardSolutionIBMKeys(t *testing.T) {
func TestRunStandardUpgradeSolution(t *testing.T) {
t.Parallel()

// Generate a 15 char long random string for the admin_pass.
randomBytes := make([]byte, 13)
_, randErr := rand.Read(randomBytes)
require.Nil(t, randErr) // do not proceed if we can't gen a random password

randomPass := "A1" + base64.URLEncoding.EncodeToString(randomBytes)[:13]

options := testhelper.TestOptionsDefault(&testhelper.TestOptions{
Testing: t,
TerraformDir: standardSolutionTerraformDir,
Expand All @@ -161,6 +171,7 @@ func TestRunStandardUpgradeSolution(t *testing.T) {
"kms_endpoint_type": "public",
"provider_visibility": "public",
"resource_group_name": options.Prefix,
"admin_pass": randomPass,
}

output, err := options.RunTestUpgrade()
Expand Down