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"
|
source = "siderolabs/talos"
|
||||||
version = "~> 0.4"
|
version = "~> 0.4"
|
||||||
}
|
}
|
||||||
libvirt = {
|
|
||||||
source = "dmacvicar/libvirt"
|
|
||||||
version = "~> 0.7"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -34,26 +30,6 @@ variable "vcpu_count" {
|
||||||
# Configure providers
|
# Configure providers
|
||||||
provider "talos" {}
|
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
|
# Generate machine secrets
|
||||||
resource "talos_machine_secrets" "this" {}
|
resource "talos_machine_secrets" "this" {}
|
||||||
|
|
||||||
|
|
@ -63,124 +39,73 @@ data "talos_machine_configuration" "this" {
|
||||||
cluster_endpoint = "https://10.5.0.2:6443"
|
cluster_endpoint = "https://10.5.0.2:6443"
|
||||||
machine_type = "controlplane"
|
machine_type = "controlplane"
|
||||||
machine_secrets = talos_machine_secrets.this.machine_secrets
|
machine_secrets = talos_machine_secrets.this.machine_secrets
|
||||||
talos_version = "v1.11.2"
|
talos_version = "v1.11.1"
|
||||||
|
|
||||||
config_patches = [
|
|
||||||
yamlencode({
|
|
||||||
machine = {
|
|
||||||
install = {
|
|
||||||
disk = "/dev/vda"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
data "talos_client_configuration" "this" {
|
data "talos_client_configuration" "this" {
|
||||||
cluster_name = "example-cluster"
|
cluster_name = var.cluster_name
|
||||||
client_configuration = talos_machine_secrets.this.client_configuration
|
client_configuration = talos_machine_secrets.this.client_configuration
|
||||||
nodes = ["10.5.0.2"]
|
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
|
# Download Talos kernel and initramfs
|
||||||
resource "null_resource" "download_talos_files" {
|
provisioner "local-exec" {
|
||||||
triggers = {
|
command = <<EOT
|
||||||
version = "v1.6.4"
|
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" {
|
provisioner "local-exec" {
|
||||||
command = <<EOT
|
command = <<EOT
|
||||||
mkdir -p _out/
|
sudo --preserve-env=HOME talosctl cluster create \
|
||||||
curl -L -o _out/vmlinuz-amd64 https://github.com/siderolabs/talos/releases/download/${self.triggers.version}/vmlinuz-amd64
|
--provisioner=qemu \
|
||||||
curl -L -o _out/initramfs-amd64.xz https://github.com/siderolabs/talos/releases/download/${self.triggers.version}/initramfs-amd64.xz
|
--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
|
EOT
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Create a disk for Talos
|
# resource "talos_machine_configuration_apply" "this" {
|
||||||
resource "libvirt_volume" "talos-disk" {
|
# client_configuration = talos_machine_secrets.this.client_configuration
|
||||||
name = "talos-disk"
|
# machine_configuration_input = data.talos_machine_configuration.this.machine_configuration
|
||||||
pool = "default"
|
# node = "10.5.0.2"
|
||||||
size = 10 * 1024 * 1024 * 1024 # 10GB
|
# }
|
||||||
format = "qcow2"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Create the QEMU domain with direct kernel boot
|
# resource "talos_machine_bootstrap" "this" {
|
||||||
resource "libvirt_domain" "talos-controlplane" {
|
# depends_on = [
|
||||||
name = "talos-controlplane"
|
# talos_machine_configuration_apply.this
|
||||||
memory = var.memory_mb
|
# ]
|
||||||
vcpu = var.vcpu_count
|
# node = "10.5.0.2"
|
||||||
|
# client_configuration = talos_machine_secrets.this.client_configuration
|
||||||
|
# }
|
||||||
|
|
||||||
# Use kernel and initramfs directly
|
# resource "talos_cluster_kubeconfig" "this" {
|
||||||
kernel = "${path.module}/_out/vmlinuz-amd64"
|
# depends_on = [
|
||||||
initrd = "${path.module}/_out/initramfs-amd64.xz"
|
# talos_machine_bootstrap.this
|
||||||
|
# ]
|
||||||
# Talos kernel parameters
|
# client_configuration = talos_machine_secrets.this.client_configuration
|
||||||
cmdline = [
|
# node = "10.5.0.2"
|
||||||
{
|
# }
|
||||||
"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"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Output important information
|
# Output important information
|
||||||
output "controlplane_ip" {
|
output "controlplane_ip" {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue