From 4e2f951f6d961003a6dd5c6918fe8f4f52b5fe78 Mon Sep 17 00:00:00 2001 From: vandomej Date: Sat, 27 Sep 2025 20:55:32 -0700 Subject: [PATCH] Trying to setup talos qemu with terraform --- README.md | 12 ++- main.tf | 189 +++++++++++++++++++++++++++++++++++++++++++++++ terraform.tfvars | 4 + 3 files changed, 204 insertions(+), 1 deletion(-) create mode 100644 main.tf create mode 100644 terraform.tfvars diff --git a/README.md b/README.md index 05d8708..b700a93 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,14 @@ -# Setup +# 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` + +# Development Environment Setup `brew install minikube` diff --git a/main.tf b/main.tf new file mode 100644 index 0000000..2eee390 --- /dev/null +++ b/main.tf @@ -0,0 +1,189 @@ +terraform { + required_version = ">= 1.0" + required_providers { + talos = { + source = "siderolabs/talos" + version = "~> 0.4" + } + libvirt = { + source = "dmacvicar/libvirt" + version = "~> 0.7" + } + } +} + +# Load variables from a .tfvars file +variable "cluster_name" { + description = "The name of the Talos cluster" + type = string + default = "evolved-npcs-cluster" +} + +variable "memory_mb" { + description = "Memory for each VM in MB" + type = number + default = 2048 +} + +variable "vcpu_count" { + description = "Number of vCPUs for each VM" + type = number + default = 2 +} + +# Configure providers +provider "talos" {} + +provider "libvirt" { + uri = "qemu:///system" +} + +# Create a dedicated network for Talos +resource "libvirt_network" "talos_network" { + name = "talos-network" + mode = "nat" + domain = "talos.local" + addresses = ["10.5.0.0/24"] + + dhcp { + enabled = true + } + + dns { + enabled = true + } +} + +# Generate machine secrets +resource "talos_machine_secrets" "this" {} + +# Create control plane configuration with correct endpoint +resource "talos_machine_configuration" "controlplane" { + cluster_name = var.cluster_name + cluster_endpoint = "https://10.5.0.0:6443" # Fixed endpoint IP + machine_type = "controlplane" + machine_secrets = talos_machine_secrets.this.machine_secrets + + config_patches = [ + yamlencode({ + machine = { + install = { + disk = "/dev/vda" + } + network = { + interfaces = [ + { + interface = "eth0" + addresses = ["10.5.0.0/24"] + } + ] + } + } + }) + ] +} + +# Download Talos kernel and initramfs +resource "null_resource" "download_talos_files" { + triggers = { + version = "v1.6.4" # Change to your preferred version + } + + provisioner "local-exec" { + command = <