From c1b0b95c13f5ecb90843bd1d7fdf9d02d91dc768 Mon Sep 17 00:00:00 2001 From: vandomej Date: Sun, 28 Sep 2025 11:26:14 -0700 Subject: [PATCH] Adding cleanup script --- README.md | 22 ++---- control_plane/README.md | 25 +++++++ control_plane/cleanup.sh | 14 ++++ main.tf => control_plane/main.tf | 70 ++++--------------- .../terraform.tfvars | 0 5 files changed, 59 insertions(+), 72 deletions(-) create mode 100644 control_plane/README.md create mode 100644 control_plane/cleanup.sh rename main.tf => control_plane/main.tf (51%) rename terraform.tfvars => control_plane/terraform.tfvars (100%) diff --git a/README.md b/README.md index 7b8853a..e2b9774 100644 --- a/README.md +++ b/README.md @@ -1,25 +1,15 @@ # Setup Instructions +Start out in the control_plane directory. + Ensure you have [Homebrew](https://brew.sh/) installed on your machine. `/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"` -Ensure you have the dependencies installed: +After you spin up the control plane, then move on to the hc_vault directory. -`brew install terraform` +After you spin up Vault, then move on to the teamcity-agent directory. -Run the following commands to initialize and apply the Terraform configuration: +Finally, you can spin up worker nodes in the worker_nodes directory. -```bash - terraform init - terraform plan - terraform apply -``` - -# Development Environment Setup - -`brew install minikube` - -```bash - minikube start --driver=podman --container-runtime=cri-o -``` \ No newline at end of file +# Development Environment Setup \ No newline at end of file diff --git a/control_plane/README.md b/control_plane/README.md new file mode 100644 index 0000000..7b8853a --- /dev/null +++ b/control_plane/README.md @@ -0,0 +1,25 @@ +# Setup Instructions + +Ensure you have [Homebrew](https://brew.sh/) installed on your machine. + +`/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"` + +Ensure you have the dependencies installed: + +`brew install terraform` + +Run the following commands to initialize and apply the Terraform configuration: + +```bash + terraform init + terraform plan + terraform apply +``` + +# Development Environment Setup + +`brew install minikube` + +```bash + minikube start --driver=podman --container-runtime=cri-o +``` \ No newline at end of file diff --git a/control_plane/cleanup.sh b/control_plane/cleanup.sh new file mode 100644 index 0000000..53c2f11 --- /dev/null +++ b/control_plane/cleanup.sh @@ -0,0 +1,14 @@ +#!/bin/bash +cluster_name="$1" + +# Remove kubeconfig entries +kubectl config delete-context "$cluster_name" 2>/dev/null || true +kubectl config delete-cluster "admin@$cluster_name" 2>/dev/null || true +kubectl config delete-user "admin@$cluster_name" 2>/dev/null || true + +talosctl config remove "$cluster_name" 2>/dev/null || true + +# Remove files +rm -rf "${HOME}/.talos/clusters/${cluster_name}" 2>/dev/null || true + +echo "Cleanup completed for cluster: $cluster_name" \ No newline at end of file diff --git a/main.tf b/control_plane/main.tf similarity index 51% rename from main.tf rename to control_plane/main.tf index cd65b8d..fee1626 100644 --- a/main.tf +++ b/control_plane/main.tf @@ -8,6 +8,7 @@ terraform { } } + # Load variables from a .tfvars file variable "cluster_name" { description = "The name of the Talos cluster" @@ -33,30 +34,19 @@ variable "talos_version" { default = "v1.11.1" } -# Configure providers -provider "talos" {} -# Generate machine secrets -resource "talos_machine_secrets" "this" {} - -# Create control plane configuration -data "talos_machine_configuration" "this" { - cluster_name = var.cluster_name - cluster_endpoint = "https://10.5.0.2:6443" - machine_type = "controlplane" - machine_secrets = talos_machine_secrets.this.machine_secrets - talos_version = var.talos_version +locals { + # Generate unique cluster name each time + unique_cluster_name = "${var.cluster_name}-${random_id.cluster_suffix.hex}" } -data "talos_client_configuration" "this" { - cluster_name = var.cluster_name - client_configuration = talos_machine_secrets.this.client_configuration - nodes = ["10.5.0.2"] +resource "random_id" "cluster_suffix" { + byte_length = 4 } resource "null_resource" "talos_cluster" { triggers = { - cluster_name = var.cluster_name + cluster_name = local.unique_cluster_name memory_mb = var.memory_mb vcpu_count = var.vcpu_count } @@ -74,7 +64,8 @@ resource "null_resource" "talos_cluster" { command = <