Created
August 24, 2021 10:46
-
-
Save zimbatm/178c5df10ea91c963113f0495ea144ed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
variable "users" { | |
type = list(string) | |
default = ["bob"] | |
} | |
resource "random_password" "passwords" { | |
for_each = toset(var.users) | |
length = 32 | |
special = false | |
} | |
locals { | |
lines = [ | |
for user in var.users : | |
"${user}:${nonsensitive(bcrypt(random_password.passwords[user].result))}" | |
] | |
htpasswd = join("\n", local.lines) | |
} | |
output "htpasswd" { | |
value = local.htpasswd | |
} | |
output "passwords" { | |
sensitive = true | |
value = random_password.passwords | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment