From 814b6903292ec5e6907622841c9a827e879bf845 Mon Sep 17 00:00:00 2001 From: vandomej Date: Sun, 28 Sep 2025 12:10:43 -0700 Subject: [PATCH] Adjusting cleanup process --- control_plane/cleanup.sh | 3 +++ control_plane/main.tf | 34 +++++++++++----------------------- 2 files changed, 14 insertions(+), 23 deletions(-) diff --git a/control_plane/cleanup.sh b/control_plane/cleanup.sh index 62b2c36..68183fd 100644 --- a/control_plane/cleanup.sh +++ b/control_plane/cleanup.sh @@ -1,5 +1,8 @@ #!/bin/bash cluster_name="$1" +echo "Starting cleanup for cluster: $cluster_name" + +sudo ifconfig bridge0 destroy || true # Remove kubeconfig entries kubectl config delete-context "$cluster_name" || true diff --git a/control_plane/main.tf b/control_plane/main.tf index 8fa7fd1..82fe4a7 100644 --- a/control_plane/main.tf +++ b/control_plane/main.tf @@ -46,9 +46,13 @@ resource "random_id" "cluster_suffix" { resource "null_resource" "talos_cluster" { triggers = { - cluster_name = local.unique_cluster_name - memory_mb = var.memory_mb - vcpu_count = var.vcpu_count + config_hash = sha1(join("", [ + var.cluster_name, + tostring(var.memory_mb), + tostring(var.vcpu_count), + var.talos_version, + filesha1("${path.module}/cleanup.sh") # Recreate if cleanup script changes + ])) } # Download Talos kernel and initramfs @@ -64,41 +68,25 @@ resource "null_resource" "talos_cluster" { command = </dev/null || echo "Cluster destroy completed or not found" - - # Wait for cleanup - sleep 3 - - # Now run the comprehensive cleanup script to remove any leftovers - echo "Running comprehensive cleanup..." - chmod +x ${path.module}/cleanup.sh - ${path.module}/cleanup.sh ${self.triggers.cluster_name} - - # Wait a bit more to ensure everything is cleaned up - sleep 2 - # Now create the cluster echo "Creating new cluster..." sudo --preserve-env=HOME talosctl cluster create \ --provisioner=qemu \ --name ${self.triggers.cluster_name} \ + --talosconfig ${path.module}/talosconfig \ --controlplanes 1 \ --workers 0 \ --memory ${self.triggers.memory_mb} \ --cpus ${self.triggers.vcpu_count} # Change ownership of the generated files in ~/.talos and ~/.kube - sudo chown -R $(whoami):admin ~/.talos - sudo chown -R $(whoami):admin ~/.kube + sudo chown -R $(whoami):admin $(HOME)/.talos + sudo chown -R $(whoami):admin $(HOME)/.kube EOT } provisioner "local-exec" { - when = destroy + when = destroyed command = <