use locals to deduplicate ssh key expressions

This commit is contained in:
phaer
2022-01-25 14:21:58 +01:00
parent 9bb945a302
commit 07ab83a09f
4 changed files with 22 additions and 14 deletions

View File

@@ -24,8 +24,8 @@ resource "hcloud_server" "first_control_plane" {
connection {
user = "root"
private_key = var.private_key == null ? null : file(var.private_key)
agent_identity = var.private_key == null ? file(var.public_key) : null
private_key = local.ssh_private_key
agent_identity = local.ssh_identity
host = self.ipv4_address
}
}
@@ -36,8 +36,8 @@ resource "hcloud_server" "first_control_plane" {
connection {
user = "root"
private_key = var.private_key == null ? null : file(var.private_key)
agent_identity = var.private_key == null ? file(var.public_key) : null
private_key = local.ssh_private_key
agent_identity = local.ssh_identity
host = self.ipv4_address
}
}
@@ -45,7 +45,7 @@ resource "hcloud_server" "first_control_plane" {
# Wait for k3os to be ready and fetch kubeconfig.yaml
provisioner "local-exec" {
command = <<-EOT
sleep 60 && ping ${self.ipv4_address} | grep --line-buffered "bytes from" | head -1 && sleep 100 && scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i ${var.private_key} rancher@${self.ipv4_address}:/etc/rancher/k3s/k3s.yaml ${path.module}/kubeconfig.yaml
sleep 60 && ping ${self.ipv4_address} | grep --line-buffered "bytes from" | head -1 && sleep 100 && scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i ${local.ssh_identity_file} rancher@${self.ipv4_address}:/etc/rancher/k3s/k3s.yaml ${path.module}/kubeconfig.yaml
sed -i -e 's/127.0.0.1/${self.ipv4_address}/g' ${path.module}/kubeconfig.yaml
EOT
}