Skip to content

Instantly share code, notes, and snippets.

@zimbatm
Created August 24, 2021 10:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zimbatm/178c5df10ea91c963113f0495ea144ed to your computer and use it in GitHub Desktop.
Save zimbatm/178c5df10ea91c963113f0495ea144ed to your computer and use it in GitHub Desktop.
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