97 lines
No EOL
2.4 KiB
HCL
97 lines
No EOL
2.4 KiB
HCL
terraform {
|
|
required_version = ">= 1.0"
|
|
required_providers {
|
|
talos = {
|
|
source = "siderolabs/talos"
|
|
version = "~> 0.4"
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
# 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
|
|
}
|
|
|
|
variable "talos_version" {
|
|
description = "The version of Talos to use"
|
|
type = string
|
|
default = "v1.11.1"
|
|
}
|
|
|
|
|
|
locals {
|
|
# Generate unique cluster name each time
|
|
unique_cluster_name = "${var.cluster_name}-${random_id.cluster_suffix.hex}"
|
|
}
|
|
|
|
resource "random_id" "cluster_suffix" {
|
|
byte_length = 4
|
|
}
|
|
|
|
resource "null_resource" "talos_cluster" {
|
|
triggers = {
|
|
cluster_name = local.unique_cluster_name
|
|
memory_mb = var.memory_mb
|
|
vcpu_count = var.vcpu_count
|
|
}
|
|
|
|
# Download Talos kernel and initramfs
|
|
provisioner "local-exec" {
|
|
command = <<EOT
|
|
mkdir -p _out/
|
|
curl -L -o _out/vmlinuz-arm64 https://github.com/siderolabs/talos/releases/download/${var.talos_version}/vmlinuz-arm64
|
|
curl -L -o _out/initramfs-arm64.xz https://github.com/siderolabs/talos/releases/download/${var.talos_version}/initramfs-arm64.xz
|
|
EOT
|
|
}
|
|
|
|
provisioner "local-exec" {
|
|
command = <<EOT
|
|
sudo --preserve-env=HOME talosctl cluster create \
|
|
--provisioner=qemu \
|
|
--name ${self.triggers.cluster_name} \
|
|
--controlplanes 1 \
|
|
--workers 0 \
|
|
--memory ${var.memory_mb} \
|
|
--cpus ${var.vcpu_count}
|
|
EOT
|
|
}
|
|
|
|
provisioner "local-exec" {
|
|
when = destroy
|
|
command = <<EOT
|
|
sudo --preserve-env=HOME talosctl cluster destroy \
|
|
--provisioner=qemu \
|
|
--name ${self.triggers.cluster_name}
|
|
|
|
# Call cleanup script
|
|
chmod +x ${path.module}/cleanup.sh
|
|
${path.module}/cleanup.sh ${self.triggers.cluster_name}
|
|
EOT
|
|
}
|
|
}
|
|
|
|
output "next_steps" {
|
|
value = <<EOT
|
|
After applying:
|
|
1. The control plane will be available at 10.5.0.2
|
|
2. The configuration is embedded in the kernel parameters
|
|
3. Terraform will automatically apply the config and bootstrap the cluster
|
|
4. Check status with: talosctl --talosconfig talosconfig version --nodes 10.5.0.2
|
|
EOT
|
|
} |