Skip to content

Commit ee3fb7b

Browse files
authored
fix: updated the logic used to randomly generate the admin password to ensure it does not start with or contain any forbidden characters (#329)
1 parent 437a468 commit ee3fb7b

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

solutions/standard/main.tf

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,14 @@ resource "random_password" "admin_password" {
162162
min_numeric = 1
163163
}
164164

165+
locals {
166+
# _- are invalid first characters
167+
# if - replace first char with J
168+
# elseif _ replace first char with K
169+
# else use asis
170+
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
171+
}
172+
165173
# create a service authorization between Secrets Manager and the target service (Elastic Search)
166174
resource "ibm_iam_authorization_policy" "secrets_manager_key_manager" {
167175
count = local.create_sm_auth_policy
@@ -204,7 +212,7 @@ locals {
204212
}
205213
]
206214

207-
admin_pass = var.admin_pass == null ? random_password.admin_password[0].result : var.admin_pass
215+
admin_pass = var.admin_pass == null ? local.admin_password : var.admin_pass
208216
admin_pass_secret = [{
209217
secret_group_name = var.prefix != null && var.admin_pass_sm_secret_group != null ? "${var.prefix}-${var.admin_pass_sm_secret_group}" : var.admin_pass_sm_secret_group
210218
existing_secret_group = var.use_existing_admin_pass_sm_secret_group

0 commit comments

Comments
 (0)