From 052acf41735398d1dbec77ec89808758d1db62a8 Mon Sep 17 00:00:00 2001 From: Thomas Hintz Date: Thu, 14 Aug 2025 07:49:40 -0700 Subject: [PATCH] Removing multi-node config from terraform. --- cl/machine-mynode.yaml.tmpl | 18 ------------ flatcar/app/lb/Caddyfile | 2 +- main.tf | 57 +++++++++---------------------------- template.tfvars | 1 - 4 files changed, 15 insertions(+), 63 deletions(-) delete mode 100644 cl/machine-mynode.yaml.tmpl diff --git a/cl/machine-mynode.yaml.tmpl b/cl/machine-mynode.yaml.tmpl deleted file mode 100644 index e15f15d..0000000 --- a/cl/machine-mynode.yaml.tmpl +++ /dev/null @@ -1,18 +0,0 @@ ---- -variant: flatcar -version: 1.1.0 -passwd: - users: - - name: core - ssh_authorized_keys: ${ssh_keys} -storage: - files: - - path: /home/core/works - mode: 0755 - contents: - inline: | - #!/bin/bash - set -euo pipefail - # This script demonstrates how templating and variable substitution works when using Terraform templates for Container Linux Configs. - hostname="$(hostname)" - echo My name is ${name} and the hostname is $${hostname} and this is updated, again 5x! diff --git a/flatcar/app/lb/Caddyfile b/flatcar/app/lb/Caddyfile index ca1d6b8..d0a7152 100644 --- a/flatcar/app/lb/Caddyfile +++ b/flatcar/app/lb/Caddyfile @@ -1,4 +1,4 @@ -mycluster-mynode.nassella.cc { +wg-easy.nassella.cc { reverse_proxy http://wg-easy:80 # tls internal diff --git a/main.tf b/main.tf index d6fab02..5b1a0f2 100644 --- a/main.tf +++ b/main.tf @@ -28,11 +28,6 @@ variable "do_token" { type = string } -variable "machines" { - type = list(string) - description = "Machine names, corresponding to machine-NAME.yaml.tmpl files" -} - variable "cluster_name" { type = string description = "Cluster name used as prefix for the machine names" @@ -99,24 +94,21 @@ resource "digitalocean_custom_image" "flatcar" { } resource "digitalocean_reserved_ip" "machine" { - for_each = toset(var.machines) - region = digitalocean_droplet.machine[each.key].region + region = digitalocean_droplet.machine.region } resource "cloudflare_dns_record" "machine" { - for_each = toset(var.machines) zone_id = var.cloudflare_zone_id - name = "${var.cluster_name}-${each.key}" - content = digitalocean_reserved_ip.machine[each.key].ip_address + name = "wg-easy" + content = digitalocean_reserved_ip.machine.ip_address type = "A" proxied = false ttl = 300 } resource "digitalocean_volume" "machine" { - for_each = toset(var.machines) region = var.datacenter - name = "${var.cluster_name}-${each.key}" + name = "${var.cluster_name}" size = 30 initial_filesystem_type = "ext4" initial_filesystem_label = "appstorage" @@ -124,57 +116,36 @@ resource "digitalocean_volume" "machine" { } resource "digitalocean_droplet" "machine" { - for_each = toset(var.machines) - name = "${var.cluster_name}-${each.key}" + name = "${var.cluster_name}" image = digitalocean_custom_image.flatcar.id region = var.datacenter size = var.server_type ssh_keys = [digitalocean_ssh_key.first.fingerprint] - # user_data = data.ct_config.machine-ignitions[each.key].rendered user_data = file("flatcar/ignition.json") lifecycle { create_before_destroy = true } } -resource "time_sleep" "wait_5_seconds" { - create_duration = "5s" +resource "time_sleep" "wait_10_seconds" { + create_duration = "10s" } resource "digitalocean_reserved_ip_assignment" "machine" { - for_each = toset(var.machines) - ip_address = digitalocean_reserved_ip.machine[each.key].ip_address - droplet_id = digitalocean_droplet.machine[each.key].id + ip_address = digitalocean_reserved_ip.machine.ip_address + droplet_id = digitalocean_droplet.machine.id # sometimes digital ocean throws an error for this resource # saying the droplet has a pending event so we delay a few seconds - depends_on = [time_sleep.wait_5_seconds] + depends_on = [time_sleep.wait_10_seconds] } resource "digitalocean_volume_attachment" "machine" { - for_each = toset(var.machines) - droplet_id = digitalocean_droplet.machine[each.key].id - volume_id = digitalocean_volume.machine[each.key].id -} - -# data "ct_config" "machine-ignitions" { -# for_each = toset(var.machines) -# content = templatefile("${path.module}/cl/machine-${each.key}.yaml.tmpl", { -# ssh_keys = jsonencode(var.ssh_keys), -# name = each.key -# }) -# strict = true -# } - -# output "ip-addresses" { -# value = { -# for key in var.machines : -# "${var.cluster_name}-${key}" => digitalocean_droplet.machine[key].ipv4_address -# } -# } + droplet_id = digitalocean_droplet.machine.id + volume_id = digitalocean_volume.machine.id +} output "domain-mappings" { value = { - for key in var.machines : - "${var.cluster_name}-${key}.${var.domain}" => digitalocean_reserved_ip.machine[key].ip_address + "wg-easy.${var.domain}" = digitalocean_reserved_ip.machine.ip_address } } diff --git a/template.tfvars b/template.tfvars index dc54580..89f092e 100644 --- a/template.tfvars +++ b/template.tfvars @@ -7,7 +7,6 @@ cloudflare_zone_id = "" cloudflare_account_id = "" cluster_name = "mycluster" -machines = ["mynode"] datacenter = "sfo3" ssh_keys = [""] # paste contents of id_rsa.pub flatcar_stable_version = "4230.2.1"