Trying to setup talos qemu with terraform
This commit is contained in:
parent
517af2d402
commit
4e2f951f6d
3 changed files with 204 additions and 1 deletions
12
README.md
12
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`
|
||||
|
||||
|
|
|
|||
189
main.tf
Normal file
189
main.tf
Normal file
|
|
@ -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 = <<EOT
|
||||
mkdir -p _out/
|
||||
curl -L -o _out/vmlinuz-amd64 https://github.com/siderolabs/talos/releases/download/${self.triggers.version}/vmlinuz-amd64
|
||||
curl -L -o _out/initramfs-amd64.xz https://github.com/siderolabs/talos/releases/download/${self.triggers.version}/initramfs-amd64.xz
|
||||
EOT
|
||||
}
|
||||
}
|
||||
|
||||
# Create a cloud-init disk for configuration
|
||||
resource "libvirt_cloudinit_disk" "commoninit" {
|
||||
name = "commoninit.iso"
|
||||
user_data = <<EOF
|
||||
#cloud-config
|
||||
EOF
|
||||
}
|
||||
|
||||
# Create the QEMU domain with direct kernel boot
|
||||
resource "libvirt_domain" "talos-controlplane" {
|
||||
name = "talos-controlplane"
|
||||
memory = vars.memory_mb
|
||||
vcpu = vars.vcpu_count
|
||||
|
||||
# Use kernel and initramfs directly
|
||||
kernel = "${path.module}/_out/vmlinuz-amd64"
|
||||
initrd = "${path.module}/_out/initramfs-amd64.xz"
|
||||
|
||||
# Talos kernel parameters
|
||||
cmdline = [
|
||||
"talos.platform=metal",
|
||||
"talos.config=http://10.5.0.1:8001/controlplane.yaml",
|
||||
"ip=10.5.0.2::10.5.0.1:255.255.255.0::eth0:off",
|
||||
"init_on_alloc=1",
|
||||
"slab_nomerge",
|
||||
"pti=on",
|
||||
"console=tty0",
|
||||
"console=ttyS0",
|
||||
"printk.devkmsg=on"
|
||||
]
|
||||
|
||||
disk {
|
||||
volume_id = libvirt_volume.talos-disk.id
|
||||
}
|
||||
|
||||
network_interface {
|
||||
network_id = libvirt_network.talos_network.id
|
||||
addresses = ["10.5.0.2"]
|
||||
hostname = "controlplane"
|
||||
}
|
||||
|
||||
# Small disk for Talos
|
||||
disk {
|
||||
file = "/tmp/talos-disk.img"
|
||||
}
|
||||
|
||||
console {
|
||||
type = "pty"
|
||||
target_port = "0"
|
||||
target_type = "serial"
|
||||
}
|
||||
|
||||
graphics {
|
||||
type = "spice"
|
||||
listen_type = "address"
|
||||
autoport = true
|
||||
}
|
||||
|
||||
depends_on = [null_resource.download_talos_files]
|
||||
}
|
||||
|
||||
# Create a small disk
|
||||
resource "libvirt_volume" "talos-disk" {
|
||||
name = "talos-disk"
|
||||
pool = "default"
|
||||
size = 10 * 1024 * 1024 * 1024 # 10GB
|
||||
format = "qcow2"
|
||||
}
|
||||
|
||||
# Output important information
|
||||
output "controlplane_ip" {
|
||||
value = "10.5.0.0"
|
||||
}
|
||||
|
||||
output "talosconfig" {
|
||||
value = talos_machine_configuration.controlplane.machine_config
|
||||
sensitive = true
|
||||
}
|
||||
|
||||
output "next_steps" {
|
||||
value = <<EOT
|
||||
After applying:
|
||||
1. The control plane will be available at 10.5.0.0
|
||||
2. Apply the configuration using talosctl:
|
||||
talosctl apply-config --insecure --nodes 10.5.0.0 --file controlplane.yaml
|
||||
3. Bootstrap the cluster:
|
||||
talosctl bootstrap --nodes 10.5.0.0
|
||||
EOT
|
||||
}
|
||||
4
terraform.tfvars
Normal file
4
terraform.tfvars
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
# You can customize these values
|
||||
cluster_name = "evolved-npcs-cluster"
|
||||
memory_mb = 2048
|
||||
vcpu_count = 2
|
||||
Loading…
Add table
Reference in a new issue