Skip to content

Commit c22c663

Browse files
authored
fix: fixed bug with logic that produced and error when passing a value for admin password (#471)
1 parent a9a6544 commit c22c663

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

solutions/standard/main.tf

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,7 @@ locals {
233233
# if - replace first char with J
234234
# elseif _ replace first char with K
235235
# else use asis
236-
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
237-
238-
# admin password to use
239-
admin_pass = var.admin_pass == null ? local.generated_admin_password : var.admin_pass
236+
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
240237
}
241238

242239
#######################################################################################################################

tests/pr_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,13 @@ func TestRunStandardSolutionSchematics(t *testing.T) {
173173
func TestRunStandardUpgradeSolution(t *testing.T) {
174174
t.Parallel()
175175

176+
// Generate a 15 char long random string for the admin_pass.
177+
randomBytes := make([]byte, 13)
178+
_, randErr := rand.Read(randomBytes)
179+
require.Nil(t, randErr) // do not proceed if we can't gen a random password
180+
181+
randomPass := "A1" + base64.URLEncoding.EncodeToString(randomBytes)[:13]
182+
176183
options := testhelper.TestOptionsDefault(&testhelper.TestOptions{
177184
Testing: t,
178185
TerraformDir: standardSolutionTerraformDir,
@@ -187,6 +194,7 @@ func TestRunStandardUpgradeSolution(t *testing.T) {
187194
"kms_endpoint_type": "public",
188195
"provider_visibility": "public",
189196
"resource_group_name": options.Prefix,
197+
"admin_pass": randomPass,
190198
}
191199

192200
output, err := options.RunTestUpgrade()

0 commit comments

Comments
 (0)