From 6fc69da0872cf531e2a26bba0c64fd7bc2e39618 Mon Sep 17 00:00:00 2001 From: kjuulh Date: Sun, 12 Jan 2025 13:28:20 +0100 Subject: [PATCH] feat: add remote node configuration --- files/node.caddy | 4 ++++ node.tf | 31 ++++++++++++++++++++++++++++++- variables.tf | 10 ++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 files/node.caddy diff --git a/files/node.caddy b/files/node.caddy new file mode 100644 index 0000000..8106980 --- /dev/null +++ b/files/node.caddy @@ -0,0 +1,4 @@ +@${name}-node ${replace(name, "_", "-")}.nodes.i.kjuulh.io +handle ${name}-node { + reverse-proxy ${ip}:80 +} diff --git a/node.tf b/node.tf index 3fa0337..cece67a 100644 --- a/node.tf +++ b/node.tf @@ -3,6 +3,11 @@ locals { hostname = var.name domain = var.domain }) + + node_config = templatefile("${path.module}/files/node.caddy", { + name = var.name + ip = var.ip_address + }) } # Create a local copy of the file, to transfer to Proxmox @@ -11,6 +16,11 @@ resource "local_file" "cloud_init_deb12_node" { filename = "${path.module}/files/user_data_cloud_init_deb12_${var.name}.cfg" } +resource "local_file" "node_caddy" { + content = local.node_config + filename = "${path.module}/files/${var.name}.caddy" +} + # Transfer the file to the Proxmox Host resource "null_resource" "cloud_init_deb12_node" { connection { @@ -30,13 +40,32 @@ resource "null_resource" "cloud_init_deb12_node" { ] } +resource "null_resource" "node_caddy_template" { + connection { + type = "ssh" + user = "root" + private_key = var.ssh_private + host = var.proxy_ip + } + + provisioner "file" { + source = local_file.node_caddy.filename + destination = "${var.proxy_location}/${var.name}.yml" + } + + depends_on = [ + local_file.node_caddy + ] +} + # Create the VM resource "proxmox_vm_qemu" "node" { ## Wait for the cloud-config file to exist depends_on = [ - null_resource.cloud_init_deb12_node + null_resource.cloud_init_deb12_node, + null_resource.node_caddy_template ] name = var.name diff --git a/variables.tf b/variables.tf index e471427..9a97f48 100644 --- a/variables.tf +++ b/variables.tf @@ -8,6 +8,16 @@ variable "proxmox_ip" { default = "10.0.11.0" } +variable "proxy_ip" { + description = "which ip to use for the caddy file" + default = "10.0.9.0" +} + +variable "proxy_location" { + description = "which where to place the files upstream" + default = "/root/wireguard/nodes" +} + variable "proxmox_node" { description = "which node is the vm associated" default = "clank-smolboks-0"