diff --git a/proxmox/archlinux/data_dns.tf b/proxmox/archlinux/data_dns.tf new file mode 100644 index 0000000..defc015 --- /dev/null +++ b/proxmox/archlinux/data_dns.tf @@ -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}" +} diff --git a/proxmox/archlinux/data_http.tf b/proxmox/archlinux/data_http.tf new file mode 100644 index 0000000..b25d43c --- /dev/null +++ b/proxmox/archlinux/data_http.tf @@ -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" +} \ No newline at end of file diff --git a/proxmox/archlinux/data_proxmox.tf b/proxmox/archlinux/data_proxmox.tf new file mode 100644 index 0000000..ab83847 --- /dev/null +++ b/proxmox/archlinux/data_proxmox.tf @@ -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 +} diff --git a/proxmox/archlinux/locals.tf b/proxmox/archlinux/locals.tf new file mode 100644 index 0000000..48afa78 --- /dev/null +++ b/proxmox/archlinux/locals.tf @@ -0,0 +1,3 @@ +locals { + arch_qcow_hash = split(" ", data.http.arch_qcow_hash.response_body)[0] +} \ No newline at end of file diff --git a/proxmox/archlinux/outputs.tf b/proxmox/archlinux/outputs.tf new file mode 100644 index 0000000..35f2da2 --- /dev/null +++ b/proxmox/archlinux/outputs.tf @@ -0,0 +1,5 @@ +output "debug" { + description = "For debugging resource or data key values" + value = local.arch_qcow_hash + sensitive = false +} \ No newline at end of file diff --git a/proxmox/archlinux/providers.tf b/proxmox/archlinux/providers.tf new file mode 100644 index 0000000..b2af1a5 --- /dev/null +++ b/proxmox/archlinux/providers.tf @@ -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" {} \ No newline at end of file diff --git a/proxmox/archlinux/resources_proxmox.tf b/proxmox/archlinux/resources_proxmox.tf new file mode 100644 index 0000000..a509650 --- /dev/null +++ b/proxmox/archlinux/resources_proxmox.tf @@ -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" +} \ No newline at end of file diff --git a/proxmox/archlinux/terraform.tf b/proxmox/archlinux/terraform.tf new file mode 100644 index 0000000..4cc457f --- /dev/null +++ b/proxmox/archlinux/terraform.tf @@ -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" + } + +} \ No newline at end of file diff --git a/proxmox/archlinux/variables.tf b/proxmox/archlinux/variables.tf new file mode 100644 index 0000000..717a0c7 --- /dev/null +++ b/proxmox/archlinux/variables.tf @@ -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 +} \ No newline at end of file diff --git a/proxmox/archlinux/vars_archlinux.auto.tfvars b/proxmox/archlinux/vars_archlinux.auto.tfvars new file mode 100644 index 0000000..6b8b6ab --- /dev/null +++ b/proxmox/archlinux/vars_archlinux.auto.tfvars @@ -0,0 +1 @@ +arch_mirror = "mirrors.mit.edu/archlinux" \ No newline at end of file diff --git a/proxmox/network.auto.tfvars b/proxmox/archlinux/vars_network.auto.tfvars similarity index 100% rename from proxmox/network.auto.tfvars rename to proxmox/archlinux/vars_network.auto.tfvars diff --git a/proxmox/archlinux/vars_vms.auto.tfvars b/proxmox/archlinux/vars_vms.auto.tfvars new file mode 100644 index 0000000..22029ce --- /dev/null +++ b/proxmox/archlinux/vars_vms.auto.tfvars @@ -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" + } +] \ No newline at end of file diff --git a/proxmox/data.tf b/proxmox/talos/data_dns.tf similarity index 68% rename from proxmox/data.tf rename to proxmox/talos/data_dns.tf index aef4a18..2763798 100644 --- a/proxmox/data.tf +++ b/proxmox/talos/data_dns.tf @@ -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" { 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 ]) host = "${each.value}.${var.local_domain}" } - - diff --git a/proxmox/talos/data_proxmox.tf b/proxmox/talos/data_proxmox.tf new file mode 100644 index 0000000..ab83847 --- /dev/null +++ b/proxmox/talos/data_proxmox.tf @@ -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 +} diff --git a/proxmox/talos.tf b/proxmox/talos/data_talos.tf similarity index 79% rename from proxmox/talos.tf rename to proxmox/talos/data_talos.tf index 989660e..65ca37b 100644 --- a/proxmox/talos.tf +++ b/proxmox/talos/data_talos.tf @@ -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" { filters = { stable_versions_only = true diff --git a/proxmox/files/talos_image_schematic.yml b/proxmox/talos/files/talos_image_schematic.yml similarity index 100% rename from proxmox/files/talos_image_schematic.yml rename to proxmox/talos/files/talos_image_schematic.yml diff --git a/proxmox/files/talos_kubespan_config.yml b/proxmox/talos/files/talos_kubespan_config.yml similarity index 100% rename from proxmox/files/talos_kubespan_config.yml rename to proxmox/talos/files/talos_kubespan_config.yml diff --git a/proxmox/locals.tf b/proxmox/talos/locals.tf similarity index 92% rename from proxmox/locals.tf rename to proxmox/talos/locals.tf index f523b01..521c44a 100644 --- a/proxmox/locals.tf +++ b/proxmox/talos/locals.tf @@ -1,5 +1,4 @@ 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] cluster_fqdn = "${var.cluster_name}.${var.local_domain}" @@ -51,4 +50,5 @@ locals { }), file("${path.root}/files/talos_kubespan_config.yml") ] 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) } } \ No newline at end of file diff --git a/proxmox/outputs.tf b/proxmox/talos/outputs.tf similarity index 79% rename from proxmox/outputs.tf rename to proxmox/talos/outputs.tf index b7e3482..4ee006e 100644 --- a/proxmox/outputs.tf +++ b/proxmox/talos/outputs.tf @@ -11,6 +11,6 @@ output "talos_schematic_id" { output "debug" { description = "For debugging resource or data key values" - value = data.talos_machine_configuration.this["cp01"] - sensitive = true + value = "chane_me" + sensitive = false } \ No newline at end of file diff --git a/proxmox/providers.tf b/proxmox/talos/providers.tf similarity index 94% rename from proxmox/providers.tf rename to proxmox/talos/providers.tf index 7342b0f..a2b759f 100644 --- a/proxmox/providers.tf +++ b/proxmox/talos/providers.tf @@ -24,4 +24,6 @@ provider "proxmox" { } provider "talos" {} -provider "dns" {} \ No newline at end of file +provider "dns" {} + +provider "http" {} \ No newline at end of file diff --git a/proxmox/files.tf b/proxmox/talos/resources_proxmox.tf similarity index 64% rename from proxmox/files.tf rename to proxmox/talos/resources_proxmox.tf index 16814dd..b859830 100644 --- a/proxmox/files.tf +++ b/proxmox/talos/resources_proxmox.tf @@ -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" { for_each = data.proxmox_virtual_environment_node.hvc01 content_type = "iso" @@ -39,9 +22,9 @@ resource "proxmox_virtual_environment_file" "talos_cloud_init" { node_name = each.value.host overwrite = true 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" } timeout_upload = 10 upload_mode = "stream" -} \ No newline at end of file +} diff --git a/proxmox/talos/resources_talos.tf b/proxmox/talos/resources_talos.tf new file mode 100644 index 0000000..0e0f311 --- /dev/null +++ b/proxmox/talos/resources_talos.tf @@ -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") +} diff --git a/proxmox/templates/talos_cluster_config.yml.tftpl b/proxmox/talos/templates/talos_cluster_config.yml.tftpl similarity index 100% rename from proxmox/templates/talos_cluster_config.yml.tftpl rename to proxmox/talos/templates/talos_cluster_config.yml.tftpl diff --git a/proxmox/templates/talos_hostname_config.yml.tftpl b/proxmox/talos/templates/talos_hostname_config.yml.tftpl similarity index 100% rename from proxmox/templates/talos_hostname_config.yml.tftpl rename to proxmox/talos/templates/talos_hostname_config.yml.tftpl diff --git a/proxmox/templates/talos_link_config.yml.tftpl b/proxmox/talos/templates/talos_link_config.yml.tftpl similarity index 100% rename from proxmox/templates/talos_link_config.yml.tftpl rename to proxmox/talos/templates/talos_link_config.yml.tftpl diff --git a/proxmox/templates/talos_machine_config.yml.tftpl b/proxmox/talos/templates/talos_machine_config.yml.tftpl similarity index 100% rename from proxmox/templates/talos_machine_config.yml.tftpl rename to proxmox/talos/templates/talos_machine_config.yml.tftpl diff --git a/proxmox/templates/talos_resolver_config.yml.tftpl b/proxmox/talos/templates/talos_resolver_config.yml.tftpl similarity index 100% rename from proxmox/templates/talos_resolver_config.yml.tftpl rename to proxmox/talos/templates/talos_resolver_config.yml.tftpl diff --git a/proxmox/templates/talos_timesync_config.yml.tftpl b/proxmox/talos/templates/talos_timesync_config.yml.tftpl similarity index 100% rename from proxmox/templates/talos_timesync_config.yml.tftpl rename to proxmox/talos/templates/talos_timesync_config.yml.tftpl diff --git a/proxmox/terraform.tf b/proxmox/talos/terraform.tf similarity index 72% rename from proxmox/terraform.tf rename to proxmox/talos/terraform.tf index 1082dc3..7aea03b 100644 --- a/proxmox/terraform.tf +++ b/proxmox/talos/terraform.tf @@ -14,10 +14,14 @@ terraform { 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/terraform.tfstate" + path = "/mnt/nfs/terraform/proxmox/talos.tfstate" } } \ No newline at end of file diff --git a/proxmox/variables.tf b/proxmox/talos/variables.tf similarity index 99% rename from proxmox/variables.tf rename to proxmox/talos/variables.tf index 2a16be5..7a9c94a 100644 --- a/proxmox/variables.tf +++ b/proxmox/talos/variables.tf @@ -80,4 +80,4 @@ variable "discovery_service_endpoint" { variable "local_domain" { type = string -} \ No newline at end of file +} diff --git a/proxmox/talos/vars_network.auto.tfvars b/proxmox/talos/vars_network.auto.tfvars new file mode 100644 index 0000000..167ef50 --- /dev/null +++ b/proxmox/talos/vars_network.auto.tfvars @@ -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" +] \ No newline at end of file diff --git a/proxmox/talos.auto.tfvars b/proxmox/talos/vars_talos.auto.tfvars similarity index 100% rename from proxmox/talos.auto.tfvars rename to proxmox/talos/vars_talos.auto.tfvars diff --git a/proxmox/vms.auto.tfvars b/proxmox/talos/vars_vms.auto.tfvars similarity index 84% rename from proxmox/vms.auto.tfvars rename to proxmox/talos/vars_vms.auto.tfvars index aee0c7c..b7d9322 100644 --- a/proxmox/vms.auto.tfvars +++ b/proxmox/talos/vars_vms.auto.tfvars @@ -15,13 +15,18 @@ vm_guests = [ role = "controlplane" }, { - host = "hv02" + host = "hv01" name = "wn01" role = "worker" }, { - host = "hv03" + host = "hv02" name = "wn02" role = "worker" + }, + { + host = "hv03" + name = "wn03" + role = "worker" } ] \ No newline at end of file