Split project

This commit is contained in:
2026-09-08 00:15:03 -04:00
parent 33dc172296
commit 02516f403a
33 changed files with 223 additions and 44 deletions
+9
View File
@@ -0,0 +1,9 @@
data "dns_a_record_set" "guests" {
for_each = toset([ for guest in var.vm_guests: guest.name ])
host = "${each.value}.${var.local_domain}"
}
data "dns_aaaa_record_set" "guests" {
for_each = toset([ for guest in var.vm_guests: guest.name ])
host = "${each.value}.${var.local_domain}"
}
+9
View File
@@ -0,0 +1,9 @@
data "http" "arch_qcow_hash" {
insecure = false
method = "GET"
retry {
attempts = 1
min_delay_ms = 5000
}
url = "https://${var.arch_mirror}/images/latest/Arch-Linux-x86_64-cloudimg.qcow2.SHA256"
}
+6
View File
@@ -0,0 +1,6 @@
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
}
+3
View File
@@ -0,0 +1,3 @@
locals {
arch_qcow_hash = split(" ", data.http.arch_qcow_hash.response_body)[0]
}
+5
View File
@@ -0,0 +1,5 @@
output "debug" {
description = "For debugging resource or data key values"
value = local.arch_qcow_hash
sensitive = false
}
+28
View File
@@ -0,0 +1,28 @@
provider "proxmox" {
endpoint = "https://hvc01.balsillie.house:443/"
insecure = false
# api_token = # Takes value from PROXMOX_VE_API_TOKEN env var
random_vm_ids = true
random_vm_id_start = 10000
random_vm_id_end = 99999
ssh {
username = "ladmin"
# SSH Private Key provided by env var PROXMOX_VE_SSH_PRIVATE_KEY
agent = false
node_address_source = "dns"
node {
name = "hv01"
address = "hv01.balsillie.house"
port = 22
}
node {
name = "hv02"
address = "hv02.balsillie.house"
port = 22
}
}
}
provider "dns" {}
provider "http" {}
+16
View File
@@ -0,0 +1,16 @@
resource "proxmox_virtual_environment_file" "arch_qcow" {
for_each = data.proxmox_virtual_environment_node.hvc01
content_type = "import"
datastore_id = "local"
node_name = each.value.id
overwrite = true
source_file {
checksum = local.arch_qcow_hash
file_name = "archlinux_cloudimg_amd64.qcow2"
insecure = false
min_tls = "1.2"
path = "https://${var.arch_mirror}/images/latest/Arch-Linux-x86_64-cloudimg.qcow2"
}
timeout_upload = 300
upload_mode = "stream"
}
+23
View File
@@ -0,0 +1,23 @@
terraform {
required_version = ">= 1.15.9"
required_providers {
proxmox = {
source = "registry.terraform.io/bpg/proxmox"
version = ">= 0.111.1"
}
dns = {
source = "registry.terraform.io/hashicorp/dns"
version = ">= 3.6.1"
}
http = {
source = "registry.terraform.io/hashicorp/http"
version = ">= 3.6.1"
}
}
backend "local" {
path = "/mnt/nfs/terraform/proxmox/archlinux.tfstate"
}
}
+52
View File
@@ -0,0 +1,52 @@
variable "vm_guests" {
type = list(object({
name = string
host = string
role = string
}))
}
variable "ipv4_gateway" {
type = string
}
variable "ipv6_gateway" {
type = string
}
variable "ipv4_ntp_servers" {
type = list(string)
}
variable "ipv6_ntp_servers" {
type = list(string)
}
variable "ipv4_subnet_mask" {
type = number
}
variable "search_domains" {
type = list(string)
}
variable "ipv4_nameservers" {
type = list(object({
address = string
}))
}
variable "ipv6_nameservers" {
type = list(object({
address = string
}))
}
variable "local_domain" {
type = string
}
variable "arch_mirror" {
type = string
}
@@ -0,0 +1 @@
arch_mirror = "mirrors.mit.edu/archlinux"
+17
View File
@@ -0,0 +1,17 @@
vm_guests = [
{
host = "hv02"
name = "ch01"
role = "container_host"
},
{
host = "hv03"
name = "ch02"
role = "container_host"
},
{
host = "hv03"
name = "dl01"
role = "download"
}
]
@@ -1,10 +1,3 @@
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
}
data "dns_a_record_set" "cluster_api" { data "dns_a_record_set" "cluster_api" {
host = local.cluster_fqdn host = local.cluster_fqdn
} }
@@ -22,5 +15,3 @@ data "dns_aaaa_record_set" "guests" {
for_each = toset([ for guest in var.vm_guests: guest.name ]) for_each = toset([ for guest in var.vm_guests: guest.name ])
host = "${each.value}.${var.local_domain}" host = "${each.value}.${var.local_domain}"
} }
+6
View File
@@ -0,0 +1,6 @@
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
}
@@ -1,11 +1,3 @@
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" { data "talos_image_factory_versions" "this" {
filters = { filters = {
stable_versions_only = true stable_versions_only = true
@@ -1,5 +1,4 @@
locals { locals {
hv01_id = [ for node in data.proxmox_virtual_environment_node.hvc01 : node if node.node_name == "hv01"][0].id
# Validate talos_version variable # Validate talos_version variable
talos_version = [ for version in data.talos_image_factory_versions.this.talos_versions : version if version == var.talos_version][0] talos_version = [ for version in data.talos_image_factory_versions.this.talos_versions : version if version == var.talos_version][0]
cluster_fqdn = "${var.cluster_name}.${var.local_domain}" cluster_fqdn = "${var.cluster_name}.${var.local_domain}"
@@ -51,4 +50,5 @@ locals {
}), }),
file("${path.root}/files/talos_kubespan_config.yml") file("${path.root}/files/talos_kubespan_config.yml")
] if contains(["controlplane", "worker"], guest.role)} ] if contains(["controlplane", "worker"], guest.role)}
machine_configs = { for guest in var.vm_guests: guest.name => nonsensitive(data.talos_machine_configuration.this[guest.name].machine_configuration) if contains(["controlplane", "worker"], guest.role) }
} }
@@ -11,6 +11,6 @@ output "talos_schematic_id" {
output "debug" { output "debug" {
description = "For debugging resource or data key values" description = "For debugging resource or data key values"
value = data.talos_machine_configuration.this["cp01"] value = "chane_me"
sensitive = true sensitive = false
} }
@@ -25,3 +25,5 @@ provider "proxmox" {
provider "talos" {} provider "talos" {}
provider "dns" {} provider "dns" {}
provider "http" {}
@@ -1,20 +1,3 @@
# 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" { resource "proxmox_virtual_environment_file" "talos_iso" {
for_each = data.proxmox_virtual_environment_node.hvc01 for_each = data.proxmox_virtual_environment_node.hvc01
content_type = "iso" content_type = "iso"
@@ -39,7 +22,7 @@ resource "proxmox_virtual_environment_file" "talos_cloud_init" {
node_name = each.value.host node_name = each.value.host
overwrite = true overwrite = true
source_raw { source_raw {
data = data.talos_machine_configuration.this[each.key].machine_configuration data = local.machine_configs[each.key]
file_name = "cloud_init_${each.key}.yml" file_name = "cloud_init_${each.key}.yml"
} }
timeout_upload = 10 timeout_upload = 10
+7
View File
@@ -0,0 +1,7 @@
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")
}
@@ -14,10 +14,14 @@ terraform {
source = "registry.terraform.io/hashicorp/dns" source = "registry.terraform.io/hashicorp/dns"
version = ">= 3.6.1" version = ">= 3.6.1"
} }
http = {
source = "registry.terraform.io/hashicorp/http"
version = ">= 3.6.1"
}
} }
backend "local" { backend "local" {
path = "/mnt/nfs/terraform/proxmox/terraform.tfstate" path = "/mnt/nfs/terraform/proxmox/talos.tfstate"
} }
} }
+20
View File
@@ -0,0 +1,20 @@
ipv4_gateway = "10.96.10.254"
ipv4_subnet_mask = 24
ipv6_gateway = "2600:4040:593d:8b10:6662:66ff:fe21:e9c4"
ipv4_nameservers = [
{address = "10.96.10.254"}
]
ipv6_nameservers = [
{address = "2600:4040:593d:8b10:6662:66ff:fe21:e9c4"}
]
local_domain = "balsillie.house"
search_domains = [
"balsillie.net",
"balsillie.house"
]
ipv4_ntp_servers = [
"10.96.10.254"
]
ipv6_ntp_servers = [
"2600:4040:593d:8b10:6662:66ff:fe21:e9c4"
]
@@ -15,13 +15,18 @@ vm_guests = [
role = "controlplane" role = "controlplane"
}, },
{ {
host = "hv02" host = "hv01"
name = "wn01" name = "wn01"
role = "worker" role = "worker"
}, },
{ {
host = "hv03" host = "hv02"
name = "wn02" name = "wn02"
role = "worker" role = "worker"
},
{
host = "hv03"
name = "wn03"
role = "worker"
} }
] ]