Updating minor issues with terraform file

This commit is contained in:
vandomej 2025-09-27 21:04:15 -07:00
parent 4e2f951f6d
commit 7273aeea4c
2 changed files with 30 additions and 41 deletions

View file

@ -8,6 +8,14 @@ Ensure you have the dependencies installed:
`brew install terraform` `brew install terraform`
Run the following commands to initialize and apply the Terraform configuration:
```bash
terraform init
terraform plan
terraform apply
```
# Development Environment Setup # Development Environment Setup
`brew install minikube` `brew install minikube`

63
main.tf
View file

@ -57,10 +57,10 @@ resource "libvirt_network" "talos_network" {
# Generate machine secrets # Generate machine secrets
resource "talos_machine_secrets" "this" {} resource "talos_machine_secrets" "this" {}
# Create control plane configuration with correct endpoint # Create control plane configuration
resource "talos_machine_configuration" "controlplane" { data "talos_machine_configuration" "controlplane" {
cluster_name = var.cluster_name cluster_name = var.cluster_name
cluster_endpoint = "https://10.5.0.0:6443" # Fixed endpoint IP 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
@ -70,14 +70,6 @@ resource "talos_machine_configuration" "controlplane" {
install = { install = {
disk = "/dev/vda" disk = "/dev/vda"
} }
network = {
interfaces = [
{
interface = "eth0"
addresses = ["10.5.0.0/24"]
}
]
}
} }
}) })
] ]
@ -86,7 +78,7 @@ resource "talos_machine_configuration" "controlplane" {
# Download Talos kernel and initramfs # Download Talos kernel and initramfs
resource "null_resource" "download_talos_files" { resource "null_resource" "download_talos_files" {
triggers = { triggers = {
version = "v1.6.4" # Change to your preferred version version = "v1.6.4"
} }
provisioner "local-exec" { provisioner "local-exec" {
@ -98,19 +90,19 @@ resource "null_resource" "download_talos_files" {
} }
} }
# Create a cloud-init disk for configuration # Create a disk for Talos
resource "libvirt_cloudinit_disk" "commoninit" { resource "libvirt_volume" "talos-disk" {
name = "commoninit.iso" name = "talos-disk"
user_data = <<EOF pool = "default"
#cloud-config size = 10 * 1024 * 1024 * 1024 # 10GB
EOF format = "qcow2"
} }
# Create the QEMU domain with direct kernel boot # Create the QEMU domain with direct kernel boot
resource "libvirt_domain" "talos-controlplane" { resource "libvirt_domain" "talos-controlplane" {
name = "talos-controlplane" name = "talos-controlplane"
memory = vars.memory_mb memory = var.memory_mb
vcpu = vars.vcpu_count vcpu = var.vcpu_count
# Use kernel and initramfs directly # Use kernel and initramfs directly
kernel = "${path.module}/_out/vmlinuz-amd64" kernel = "${path.module}/_out/vmlinuz-amd64"
@ -119,7 +111,7 @@ resource "libvirt_domain" "talos-controlplane" {
# Talos kernel parameters # Talos kernel parameters
cmdline = [ cmdline = [
"talos.platform=metal", "talos.platform=metal",
"talos.config=http://10.5.0.1:8001/controlplane.yaml", "talos.config=${base64encode(data.talos_machine_configuration.controlplane.machine_config)}",
"ip=10.5.0.2::10.5.0.1:255.255.255.0::eth0:off", "ip=10.5.0.2::10.5.0.1:255.255.255.0::eth0:off",
"init_on_alloc=1", "init_on_alloc=1",
"slab_nomerge", "slab_nomerge",
@ -139,11 +131,6 @@ resource "libvirt_domain" "talos-controlplane" {
hostname = "controlplane" hostname = "controlplane"
} }
# Small disk for Talos
disk {
file = "/tmp/talos-disk.img"
}
console { console {
type = "pty" type = "pty"
target_port = "0" target_port = "0"
@ -159,31 +146,25 @@ resource "libvirt_domain" "talos-controlplane" {
depends_on = [null_resource.download_talos_files] 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 important information
output "controlplane_ip" { output "controlplane_ip" {
value = "10.5.0.0" value = "10.5.0.2"
} }
output "talosconfig" { output "talosconfig" {
value = talos_machine_configuration.controlplane.machine_config value = data.talos_machine_configuration.controlplane.machine_config
sensitive = true sensitive = true
} }
output "next_steps" { output "next_steps" {
value = <<EOT value = <<EOT
After applying: After applying:
1. The control plane will be available at 10.5.0.0 1. The control plane will be available at 10.5.0.2
2. Apply the configuration using talosctl: 2. The configuration is embedded in the kernel parameters
talosctl apply-config --insecure --nodes 10.5.0.0 --file controlplane.yaml 3. Wait for Talos to install and reboot
3. Bootstrap the cluster: 4. Bootstrap the cluster:
talosctl bootstrap --nodes 10.5.0.0 talosctl bootstrap --nodes 10.5.0.2
5. Get kubeconfig:
talosctl kubeconfig --nodes 10.5.0.2
EOT EOT
} }