Skip to content

Instantly share code, notes, and snippets.

@liamkinne
Created December 11, 2022 17:34
Show Gist options
  • Save liamkinne/c67cd470a824a1045577d5b34a0423f7 to your computer and use it in GitHub Desktop.
Save liamkinne/c67cd470a824a1045577d5b34a0423f7 to your computer and use it in GitHub Desktop.
Generate kubeadmin credentials secret with Terraform
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