diff --git a/proxmox/data.tf b/proxmox/data.tf index 070da3e..ab83847 100644 --- a/proxmox/data.tf +++ b/proxmox/data.tf @@ -1,4 +1,6 @@ -data "proxmox_vm" "ch01" { - id = 100 - node_name = "hv01" -} \ No newline at end of file +data "proxmox_virtual_environment_nodes" "hvc01" {} + +data "proxmox_virtual_environment_node" "hvc01" { + for_each = toset(data.proxmox_virtual_environment_nodes.hvc01.names) + node_name = each.value +} diff --git a/proxmox/files.tf b/proxmox/files.tf new file mode 100644 index 0000000..e36f775 --- /dev/null +++ b/proxmox/files.tf @@ -0,0 +1,31 @@ +# resource "proxmox_virtual_environment_file" "cloud_init_user_data" { +# for_each = toset(var.vm_guests) +# content_type = "snippets" +# datastore_id = "local" +# file_mode = 0666 +# node_name = each.value.host +# overwrite = true +# source_raw { +# data = templatefile() +# file_name = "cloud_init_user_data_${each.value.name}.yml" +# } +# timeout_upload = 10 +# upload_mode = "stream" +# } + +resource "proxmox_virtual_environment_file" "talos_iso" { + for_each = data.proxmox_virtual_environment_node.hvc01 + content_type = "iso" + datastore_id = "local" + node_name = each.value.id + overwrite = false + source_file { + # checksum = + file_name = "talos_${local.talos_version}.iso" + insecure = false + min_tls = "1.2" + path = data.talos_image_factory_urls.this.urls.iso_secureboot + } + timeout_upload = 120 + # upload_mode = # N/A, has no effect when content_type = iso +} \ No newline at end of file diff --git a/proxmox/files/talos_image_schematic.yml b/proxmox/files/talos_image_schematic.yml new file mode 100644 index 0000000..ee7c418 --- /dev/null +++ b/proxmox/files/talos_image_schematic.yml @@ -0,0 +1,16 @@ +customization: + systemExtensions: + officialExtensions: + - siderolabs/amd-ucode + - siderolabs/amdgpu + - siderolabs/i915 + - siderolabs/intel-ucode + - siderolabs/lldpd + - siderolabs/nfs-utils + - siderolabs/nfsd + - siderolabs/nfsrahead + - siderolabs/nut-client + - siderolabs/nvme-cli + - siderolabs/qemu-guest-agent + - siderolabs/xe + bootloader: sd-boot \ No newline at end of file diff --git a/proxmox/locals.tf b/proxmox/locals.tf new file mode 100644 index 0000000..3d37243 --- /dev/null +++ b/proxmox/locals.tf @@ -0,0 +1,5 @@ +locals { + hv01_id = [ for node in data.proxmox_virtual_environment_node.hvc01 : node if node.node_name == "hv01"][0].id + # Validate talos_version variable + talos_version = [ for version in data.talos_image_factory_versions.this.talos_versions : version if version == var.talos_version][0] +} \ No newline at end of file diff --git a/proxmox/outputs.tf b/proxmox/outputs.tf index 15e0c22..ab4afc8 100644 --- a/proxmox/outputs.tf +++ b/proxmox/outputs.tf @@ -1,6 +1,15 @@ -output "ch01" { - description = "Container Host 01 VM details" - value = { - status = data.proxmox_vm.ch01.status - } +# output "ch01" { +# description = "Container Host 01 VM details" +# value = { +# status = data.proxmox_vm.ch01.status +# } +# } + +output "talos_schematic_id" { + value = talos_image_factory_schematic.this.id +} + +output "debug" { + description = "For debugging resource or data key values" + value = data.talos_image_factory_urls.this.urls } \ No newline at end of file diff --git a/proxmox/plan.tfplan b/proxmox/plan.tfplan new file mode 100644 index 0000000..91912a4 Binary files /dev/null and b/proxmox/plan.tfplan differ diff --git a/proxmox/providers.tf b/proxmox/providers.tf index 268c621..edbf9c5 100644 --- a/proxmox/providers.tf +++ b/proxmox/providers.tf @@ -5,4 +5,20 @@ provider "proxmox" { random_vm_ids = true random_vm_id_start = 10000 random_vm_id_end = 99999 -} \ No newline at end of file + ssh { + username = "ladmin" + agent = true + node_address_source = "dns" + node { + name = "hv01" + address = "hv01.balsillie.house" + port = 22 + } + node { + name = "hv02" + address = "hv02.balsillie.house" + port = 22 + } + } +} +provider "talos" {} \ No newline at end of file diff --git a/proxmox/talos.auto.tfvars b/proxmox/talos.auto.tfvars new file mode 100644 index 0000000..d4c13f7 --- /dev/null +++ b/proxmox/talos.auto.tfvars @@ -0,0 +1,2 @@ +talos_version = "v1.13.9" +cluster_endpoint = "https://k8s01.balsillie.house:6443" \ No newline at end of file diff --git a/proxmox/talos.tf b/proxmox/talos.tf new file mode 100644 index 0000000..0f3d5c8 --- /dev/null +++ b/proxmox/talos.tf @@ -0,0 +1,19 @@ +resource "talos_machine_secrets" "this" { + talos_version = local.talos_version +} + +resource "talos_image_factory_schematic" "this" { + schematic = file("${path.root}/files/talos_image_schematic.yml") +} + +data "talos_image_factory_versions" "this" { + filters = { + stable_versions_only = true + } +} + +data "talos_image_factory_urls" "this" { + talos_version = local.talos_version + schematic_id = talos_image_factory_schematic.this.id + platform = "nocloud" +} \ No newline at end of file diff --git a/proxmox/templates/control_plane_user_data.tftpl b/proxmox/templates/control_plane_user_data.tftpl new file mode 100644 index 0000000..5b5b756 --- /dev/null +++ b/proxmox/templates/control_plane_user_data.tftpl @@ -0,0 +1,27 @@ +cluster: + id: + secret: + token: + endpoint: https://:6443 + +machine: + type: controlplane + token: + kubelet: + image: ghcr.io/siderolabs/kubelet:v1.29.0 + install: + disk: /dev/sda + image: ghcr.io/siderolabs/installer:v1.6.0 + bootLOADER: grub + network: + interfaces: + - interface: eth0 + dhcp: true + nameservers: + - 8.8.8.8 + sysctls: + fs.inotify.max_user_watches: "1048576" + features: + rbac: true + stableHostname: true + appArmor: true \ No newline at end of file diff --git a/proxmox/terraform.tf b/proxmox/terraform.tf index 85032e4..9a3aa62 100644 --- a/proxmox/terraform.tf +++ b/proxmox/terraform.tf @@ -6,10 +6,14 @@ terraform { source = "registry.terraform.io/bpg/proxmox" version = ">= 0.111.1" } + talos = { + source = "registry.terraform.io/siderolabs/talos" + version = "0.11.0" + } } backend "local" { path = "/mnt/nfs/terraform/proxmox/terraform.tfstate" } - + } \ No newline at end of file diff --git a/proxmox/variables.tf b/proxmox/variables.tf new file mode 100644 index 0000000..b3992dc --- /dev/null +++ b/proxmox/variables.tf @@ -0,0 +1,18 @@ +variable "vm_guests" { + type = list(object({ + name = string + host = string + ipv4_address = string + role = string + cpu = number + memory = number + })) +} + +variable "talos_version" { + type = string +} + +variable "cluster_endpoint" { + type = string +} \ No newline at end of file diff --git a/proxmox/vms.auto.tfvars b/proxmox/vms.auto.tfvars new file mode 100644 index 0000000..0d1c0be --- /dev/null +++ b/proxmox/vms.auto.tfvars @@ -0,0 +1,10 @@ +vm_guests = [ + { + cpu = 1 + host = "hv01" + ipv4_address = "10.96.10.61" + memory = 4096 + name = "k8s01-cp01" + role = "talos_control_plane" + } +] \ No newline at end of file