Trying command line execution instead of terraform provider
This commit is contained in:
parent
ed6337ac18
commit
137c6f5e84
1 changed files with 49 additions and 124 deletions
171
main.tf
171
main.tf
|
|
@ -5,10 +5,6 @@ terraform {
|
|||
source = "siderolabs/talos"
|
||||
version = "~> 0.4"
|
||||
}
|
||||
libvirt = {
|
||||
source = "dmacvicar/libvirt"
|
||||
version = "~> 0.7"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -34,26 +30,6 @@ variable "vcpu_count" {
|
|||
# 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" {}
|
||||
|
||||
|
|
@ -63,124 +39,73 @@ data "talos_machine_configuration" "this" {
|
|||
cluster_endpoint = "https://10.5.0.2:6443"
|
||||
machine_type = "controlplane"
|
||||
machine_secrets = talos_machine_secrets.this.machine_secrets
|
||||
talos_version = "v1.11.2"
|
||||
|
||||
config_patches = [
|
||||
yamlencode({
|
||||
machine = {
|
||||
install = {
|
||||
disk = "/dev/vda"
|
||||
}
|
||||
}
|
||||
})
|
||||
]
|
||||
talos_version = "v1.11.1"
|
||||
}
|
||||
|
||||
data "talos_client_configuration" "this" {
|
||||
cluster_name = "example-cluster"
|
||||
cluster_name = var.cluster_name
|
||||
client_configuration = talos_machine_secrets.this.client_configuration
|
||||
nodes = ["10.5.0.2"]
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
resource "null_resource" "talos_cluster" {
|
||||
triggers = {
|
||||
cluster_name = var.cluster_name
|
||||
memory_mb = var.memory_mb
|
||||
vcpu_count = var.vcpu_count
|
||||
}
|
||||
|
||||
# Download Talos kernel and initramfs
|
||||
resource "null_resource" "download_talos_files" {
|
||||
triggers = {
|
||||
version = "v1.6.4"
|
||||
provisioner "local-exec" {
|
||||
command = <<EOT
|
||||
mkdir -p _out/
|
||||
curl -L -o _out/vmlinuz-arm64 https://github.com/siderolabs/talos/releases/download/${self.triggers.version}/vmlinuz-arm64
|
||||
curl -L -o _out/initramfs-arm64.xz https://github.com/siderolabs/talos/releases/download/${self.triggers.version}/initramfs-arm64.xz
|
||||
EOT
|
||||
}
|
||||
|
||||
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
|
||||
sudo --preserve-env=HOME talosctl cluster create \
|
||||
--provisioner=qemu \
|
||||
--name ${var.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 \
|
||||
--name ${self.triggers.cluster_name}
|
||||
EOT
|
||||
}
|
||||
}
|
||||
|
||||
# Create a disk for Talos
|
||||
resource "libvirt_volume" "talos-disk" {
|
||||
name = "talos-disk"
|
||||
pool = "default"
|
||||
size = 10 * 1024 * 1024 * 1024 # 10GB
|
||||
format = "qcow2"
|
||||
}
|
||||
# resource "talos_machine_configuration_apply" "this" {
|
||||
# client_configuration = talos_machine_secrets.this.client_configuration
|
||||
# machine_configuration_input = data.talos_machine_configuration.this.machine_configuration
|
||||
# node = "10.5.0.2"
|
||||
# }
|
||||
|
||||
# Create the QEMU domain with direct kernel boot
|
||||
resource "libvirt_domain" "talos-controlplane" {
|
||||
name = "talos-controlplane"
|
||||
memory = var.memory_mb
|
||||
vcpu = var.vcpu_count
|
||||
# resource "talos_machine_bootstrap" "this" {
|
||||
# depends_on = [
|
||||
# talos_machine_configuration_apply.this
|
||||
# ]
|
||||
# node = "10.5.0.2"
|
||||
# client_configuration = talos_machine_secrets.this.client_configuration
|
||||
# }
|
||||
|
||||
# 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" = base64encode(data.talos_machine_configuration.this.machine_configuration) # FIXED: Correct attribute
|
||||
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"
|
||||
}
|
||||
|
||||
console {
|
||||
type = "pty"
|
||||
target_port = "0"
|
||||
target_type = "serial"
|
||||
}
|
||||
|
||||
graphics {
|
||||
type = "spice"
|
||||
listen_type = "address"
|
||||
autoport = true
|
||||
}
|
||||
|
||||
depends_on = [null_resource.download_talos_files]
|
||||
}
|
||||
|
||||
resource "talos_machine_configuration_apply" "this" {
|
||||
depends_on = [libvirt_domain.talos-controlplane]
|
||||
client_configuration = talos_machine_secrets.this.client_configuration
|
||||
machine_configuration_input = data.talos_machine_configuration.this.machine_configuration
|
||||
node = "10.5.0.2"
|
||||
}
|
||||
|
||||
resource "talos_machine_bootstrap" "this" {
|
||||
depends_on = [
|
||||
talos_machine_configuration_apply.this
|
||||
]
|
||||
node = "10.5.0.2"
|
||||
client_configuration = talos_machine_secrets.this.client_configuration
|
||||
}
|
||||
|
||||
resource "talos_cluster_kubeconfig" "this" {
|
||||
depends_on = [
|
||||
talos_machine_bootstrap.this
|
||||
]
|
||||
client_configuration = talos_machine_secrets.this.client_configuration
|
||||
node = "10.5.0.2"
|
||||
}
|
||||
# resource "talos_cluster_kubeconfig" "this" {
|
||||
# depends_on = [
|
||||
# talos_machine_bootstrap.this
|
||||
# ]
|
||||
# client_configuration = talos_machine_secrets.this.client_configuration
|
||||
# node = "10.5.0.2"
|
||||
# }
|
||||
|
||||
# Output important information
|
||||
output "controlplane_ip" {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue