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`
Run the following commands to initialize and apply the Terraform configuration:
```bash
terraform init
terraform plan
terraform apply
```
# Development Environment Setup
`brew install minikube`

63
main.tf
View file

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