Skip to content

Commit

Permalink
Sshprivate key (#34)
Browse files Browse the repository at this point in the history
* private_key expl

* ssh agent within context
  • Loading branch information
JWDobken authored Oct 19, 2022
1 parent 268ac84 commit 5bdc6ac
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions modules/kubernetes/kubeadm_join.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@ resource "null_resource" "kubeadm_join" {

provisioner "local-exec" {
command = <<EOT
eval "$(ssh-agent -s)"
echo "${var.private_key}" | tr -d '\r' | ssh-add -
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
root@${local.control_plane_ip} 'echo $(kubeadm token create) > /tmp/kubeadm_token'
EOT
}

provisioner "local-exec" {
command = <<EOT
eval "$(ssh-agent -s)"
echo "${var.private_key}" | tr -d '\r' | ssh-add -
scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
root@${local.control_plane_ip}:/tmp/kubeadm_token \
/tmp/kubeadm_token
Expand Down
10 changes: 10 additions & 0 deletions modules/kubernetes/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ module "kubeconfig" {
trigger = element(var.control_plane_nodes.*.ipv4_address, 0)

command = <<EOT
eval "$(ssh-agent -s)" > /dev/null
echo "${var.private_key}" | tr -d '\r' | ssh-add - > /dev/null
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
root@${local.control_plane_ip} 'cat /root/.kube/config'
EOT
Expand All @@ -122,6 +124,8 @@ module "endpoint" {
trigger = element(var.control_plane_nodes.*.ipv4_address, 0)

command = <<EOT
eval "$(ssh-agent -s)" > /dev/null
echo "${var.private_key}" | tr -d '\r' | ssh-add - > /dev/null
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
root@${local.control_plane_ip} 'kubectl config --kubeconfig /root/.kube/config view -o jsonpath='{.clusters[0].cluster.server}''
EOT
Expand All @@ -134,6 +138,8 @@ module "certificate_authority_data" {
trigger = element(var.control_plane_nodes.*.ipv4_address, 0)

command = <<EOT
eval "$(ssh-agent -s)" > /dev/null
echo "${var.private_key}" | tr -d '\r' | ssh-add - > /dev/null
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
root@${local.control_plane_ip} 'kubectl config --kubeconfig /root/.kube/config view --flatten -o jsonpath='{.clusters[0].cluster.certificate-authority-data}''
EOT
Expand All @@ -146,6 +152,8 @@ module "client_certificate_data" {
trigger = element(var.control_plane_nodes.*.ipv4_address, 0)

command = <<EOT
eval "$(ssh-agent -s)" > /dev/null
echo "${var.private_key}" | tr -d '\r' | ssh-add - > /dev/null
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
root@${local.control_plane_ip} 'kubectl config --kubeconfig /root/.kube/config view --flatten -o jsonpath='{.users[0].user.client-certificate-data}''
EOT
Expand All @@ -158,6 +166,8 @@ module "client_key_data" {
trigger = element(var.control_plane_nodes.*.ipv4_address, 0)

command = <<EOT
eval "$(ssh-agent -s)" > /dev/null
echo "${var.private_key}" | tr -d '\r' | ssh-add - > /dev/null
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
root@${local.control_plane_ip} 'kubectl config --kubeconfig /root/.kube/config view --flatten -o jsonpath='{.users[0].user.client-key-data}''
EOT
Expand Down

0 comments on commit 5bdc6ac

Please sign in to comment.