From 98bc0754ccfc8a44990bf7732d324c380d175bac Mon Sep 17 00:00:00 2001 From: Kiara Grouwstra Date: Sun, 19 Oct 2025 19:22:21 +0200 Subject: [PATCH] factor out await.ssh Signed-off-by: Kiara Grouwstra --- deployment/run/tf-proxmox/await-ssh.sh | 31 ++++++++++++++++++++++++++ deployment/run/tf-proxmox/main.tf | 18 +-------------- 2 files changed, 32 insertions(+), 17 deletions(-) create mode 100644 deployment/run/tf-proxmox/await-ssh.sh diff --git a/deployment/run/tf-proxmox/await-ssh.sh b/deployment/run/tf-proxmox/await-ssh.sh new file mode 100644 index 00000000..448deb09 --- /dev/null +++ b/deployment/run/tf-proxmox/await-ssh.sh @@ -0,0 +1,31 @@ +#! /usr/bin/env bash +set -xeuo pipefail +declare username host key_file ssh_opts +readarray -t ssh_opts < <(echo "$ssh_opts" | jq -r '.[]') + +sshOpts=( + -o BatchMode=yes \ + -o StrictHostKeyChecking=no \ + -o ConnectTimeout=5 \ + -o ServerAliveInterval=5 \ +) +if [[ -n "${key_file}" ]]; then + sshOpts+=( + -i "${key_file}" + ) +fi +for ssh_opt in "${ssh_opts[@]}"; do + sshOpts+=( + -o "${ssh_opt}" + ) +done + +for i in $(seq 1 30); do + if ssh "${sshOpts[@]}" "${username}@${host}" "true"; then + exit 0 + fi + echo "Waiting for SSH (attempt #$i)..." + sleep 5 +done +echo "SSH never came up!" >&2 +exit 1 diff --git a/deployment/run/tf-proxmox/main.tf b/deployment/run/tf-proxmox/main.tf index f5f0f8bc..6d00e7a3 100644 --- a/deployment/run/tf-proxmox/main.tf +++ b/deployment/run/tf-proxmox/main.tf @@ -182,23 +182,7 @@ resource "null_resource" "wait_for_ssh" { proxmox_virtual_environment_vm.nix_vm ] provisioner "local-exec" { - command = <<-EOT - for i in $(seq 1 30); do - if ssh -vvv \ - -i "${var.key_file}" \ - -o BatchMode=yes \ - -o StrictHostKeyChecking=no \ - -o ConnectTimeout=1 \ - -o ServerAliveInterval=1 \ - root@${proxmox_virtual_environment_vm.nix_vm.ipv4_addresses[1][0]} "true"; then - exit 0 - fi - echo "Waiting for SSH (attempt #$i)..." - sleep 5 - done - echo "SSH never came up!" >&2 - exit 1 - EOT + command = "username=root host=${proxmox_virtual_environment_vm.nix_vm.ipv4_addresses[1][0]} key_file=${var.key_file} ssh_opts='${var.ssh_opts}' ./await-ssh.sh" } }