121 lines
No EOL
2.9 KiB
HCL
121 lines
No EOL
2.9 KiB
HCL
terraform {
|
|
required_version = ">= 1.0"
|
|
required_providers {
|
|
talos = {
|
|
source = "siderolabs/talos"
|
|
version = "~> 0.9"
|
|
}
|
|
libvirt = {
|
|
source = "dmacvicar/libvirt"
|
|
version = "~> 0.7"
|
|
}
|
|
}
|
|
}
|
|
|
|
provider "libvirt" {
|
|
uri = "qemu:///system"
|
|
}
|
|
|
|
# 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"
|
|
}
|
|
|
|
resource "libvirt_network" "talos_bridge" {
|
|
name = "control-plane-net"
|
|
autostart = true
|
|
|
|
xml {
|
|
xslt = file("control-plane-net.xsl")
|
|
}
|
|
}
|
|
|
|
resource "libvirt_pool" "talos-images" {
|
|
name = "talos-images"
|
|
type = "dir"
|
|
target {
|
|
path = "/var/lib/libvirt/images/talos-kvm"
|
|
}
|
|
}
|
|
|
|
# Download the ISO
|
|
resource "libvirt_volume" "talos_iso" {
|
|
name = "talos-metal-arm64.iso"
|
|
pool = "talos-images"
|
|
source = "https://factory.talos.dev/image/4a0d65c669d46663f377e7161e50cfd570c401f26fd9e7bda34a0216b6f1922b/v1.11.1/metal-arm64.iso"
|
|
format = "raw"
|
|
}
|
|
|
|
# Create disk for VM
|
|
resource "libvirt_volume" "control_plane_disk" {
|
|
name = "control-plane-node-1-disk.qcow2"
|
|
pool = "talos-images"
|
|
base_volume_id = libvirt_volume.talos_iso.id
|
|
size = 42949672960 # 40GB in bytes
|
|
format = "qcow2"
|
|
}
|
|
|
|
# Create the VM
|
|
resource "null_resource" "control_plane_node_1" {
|
|
depends_on = [
|
|
libvirt_network.talos_bridge,
|
|
libvirt_volume.control_plane_disk,
|
|
libvirt_volume.talos_iso
|
|
]
|
|
|
|
triggers = {
|
|
cpus = var.vcpu_count,
|
|
memory = var.memory_mb,
|
|
cluster_name = var.cluster_name
|
|
}
|
|
|
|
provisioner "local-exec" {
|
|
command = <<EOT
|
|
virt-install \
|
|
--connect=qemu:///system \
|
|
--virt-type kvm \
|
|
--name ${self.triggers.cluster_name} \
|
|
--ram ${self.triggers.memory} \
|
|
--vcpus ${self.triggers.cpus} \
|
|
--disk path=/var/lib/libvirt/images/talos-kvm/control-plane-node-1-disk.qcow2,bus=virtio,size=40,format=qcow2 \
|
|
--cdrom /var/lib/libvirt/images/talos-kvm/metal-arm64.iso \
|
|
--os-variant=linux2022 \
|
|
--network network=control-plane-net \
|
|
--graphics none \
|
|
--boot hd,cdrom \
|
|
--noautoconsole
|
|
|
|
virsh --connect=qemu:///system autostart ${self.triggers.cluster_name}
|
|
EOT
|
|
}
|
|
|
|
provisioner "local-exec" {
|
|
when = destroyed
|
|
|
|
command = <<EOT
|
|
sudo rm -f /var/lib/libvirt/qemu/nvram/${self.triggers.cluster_name}_VARS.qcow2
|
|
virsh --connect=qemu:///system destroy ${self.triggers.cluster_name}
|
|
virsh --connect=qemu:///system undefine --remove-all-storage ${self.triggers.cluster_name}
|
|
EOT
|
|
}
|
|
} |