From 0beaf2f1f2d21712b47360547a54bbdd5e8ff13b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Petazzoni?= Date: Mon, 17 Nov 2025 15:31:25 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=9B=9C=20Generate=20HAProxy=20configurati?= =?UTF-8?q?on=20for=20Proxmox=20IPv6=20scenario?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../virtual-machines/proxmox/haproxy.tf | 37 +++++++++++++++++++ .../virtual-machines/proxmox/main.tf | 1 - .../virtual-machines/proxmox/tfvars.example | 7 +++- 3 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 prepare-labs/terraform/virtual-machines/proxmox/haproxy.tf diff --git a/prepare-labs/terraform/virtual-machines/proxmox/haproxy.tf b/prepare-labs/terraform/virtual-machines/proxmox/haproxy.tf new file mode 100644 index 00000000..5255af74 --- /dev/null +++ b/prepare-labs/terraform/virtual-machines/proxmox/haproxy.tf @@ -0,0 +1,37 @@ +# If we deploy in IPv6-only environments, and the students don't have IPv6 +# connectivity, we want to offer a way to connect anyway. Our solution is +# to generate an HAProxy configuration snippet, that can be copied to a +# DualStack machine which will act as a proxy to our IPv6 machines. +# Note that the snippet still has to be copied, so this is not a 100% +# streamlined solution! + +locals { + portmaps = { + for key, value in local.nodes : + (10000 + proxmox_virtual_environment_vm._[key].vm_id) => local.ip_addresses[key] + } +} + +resource "local_file" "haproxy" { + filename = "./${var.tag}.cfg" + file_permission = "0644" + content = join("\n", [for port, address in local.portmaps : <<-EOT + frontend f${port} + bind *:${port} + default_backend b${port} + backend b${port} + mode tcp + server s${port} [${address}]:22 maxconn 16 + EOT + ]) +} + +resource "local_file" "sshproxy" { + filename = "sshproxy.txt" + file_permission = "0644" + content = join("", [ + for cid in range(1, 1 + var.how_many_clusters) : + format("ssh -l k8s -p %d\n", proxmox_virtual_environment_vm._[format("c%03dn%03d", cid, 1)].vm_id + 10000) + ]) +} + diff --git a/prepare-labs/terraform/virtual-machines/proxmox/main.tf b/prepare-labs/terraform/virtual-machines/proxmox/main.tf index a978b5f1..b141ee30 100644 --- a/prepare-labs/terraform/virtual-machines/proxmox/main.tf +++ b/prepare-labs/terraform/virtual-machines/proxmox/main.tf @@ -111,4 +111,3 @@ locals { addr if addr != "127.0.0.1" && addr != "::1"][0] } } - diff --git a/prepare-labs/terraform/virtual-machines/proxmox/tfvars.example b/prepare-labs/terraform/virtual-machines/proxmox/tfvars.example index 837b9826..ed4cf5f8 100644 --- a/prepare-labs/terraform/virtual-machines/proxmox/tfvars.example +++ b/prepare-labs/terraform/virtual-machines/proxmox/tfvars.example @@ -10,8 +10,11 @@ proxmox_password = "CHANGEME" # Which storage to use for VM disks. Defaults to "local". #proxmox_storage = "ceph" +#proxmox_storage = "local-zfs" -proxmox_template_node_name = "CHANGEME" -proxmox_template_vm_id = CHANGEME +# We recently rewrote the Proxmox configurations to automatically +# detect which template to use; so these variables aren't used anymore. +#proxmox_template_node_name = "CHANGEME" +#proxmox_template_vm_id = CHANGEME