Created
December 11, 2022 17:34
-
-
Save liamkinne/c67cd470a824a1045577d5b34a0423f7 to your computer and use it in GitHub Desktop.
Generate kubeadmin credentials secret with Terraform
This file contains hidden or 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
resource "random_password" "password" { | |
count = 4 | |
length = 5 | |
special = false | |
} | |
locals { | |
password = "${random_password.password[0].result}-${random_password.password[1].result}-${random_password.password[2].result}-${random_password.password[3].result}" | |
password_hash = bcrypt(local.password) | |
} | |
output "password" { | |
value = local.password | |
sensitive = true | |
} | |
output "password_hash" { | |
value = local.password_hash | |
sensitive = true | |
} | |
# output password: | |
# terraform output -raw password | |
# apply password hash: | |
# kubectl patch secret -n kube-system kubeadmin --type json -p '[{"op": "replace", "path": "/data/kubeadmin", "value": $(terraform output password_hash)}]' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment