terraform { required_providers { proxmox = { source = "bpg/proxmox", version = "~>0.56.1" } random = { source = "hashicorp/random" } local = { source = "hashicorp/local" } } required_version = ">=1.6.2" } module "sshd" { source = "../sshd" address_family = "inet" } locals { data_device_path = "/dev/disk/by-path/pci-0000:00:0a.0" data_disk = { device = local.data_device_path partitions = [ { label = "caddy_data" number = 1 startMiB = 0 sizeMiB = 100 typeGuid = "0FC63DAF-8483-4772-8E79-3D69D8477DE4" resize = true }, { label = "dhcp_config" number = 2 startMiB = 0 sizeMiB = 10 typeGuid= "0FC63DAF-8483-4772-8E79-3D69D8477DE4" resize = true }, { label = "dhcp_data" number = 3 startMiB = 0 sizeMiB = 10 typeGuid= "0FC63DAF-8483-4772-8E79-3D69D8477DE4" resize = true }, { label = "fcos_images" number = 4 startMiB = 0 sizeMiB = 8192 typeGuid= "0FC63DAF-8483-4772-8E79-3D69D8477DE4" resize = true }, { label = "ign_files" number = 5 startMiB = 0 sizeMiB = 512 typeGuid= "0FC63DAF-8483-4772-8E79-3D69D8477DE4" resize = true }, { label = "ssh_keys" number = 6 startMiB = 0 sizeMiB = 10 typeGuid= "0FC63DAF-8483-4772-8E79-3D69D8477DE4" resize = true } ] } hostname_file = { path = "/etc/hostname" user = {id = 0} group = {id = 0} mode = 420 #0644 contents = { source = format( "data:text/plain;base64,%s", base64encode(var.hostname), ) } } network_config_file = { path = "/etc/NetworkManager/system-connections/${var.dhcp_iface}.nmconnection" user = {id = 0} group = {id = 0} mode = 384 #0600 contents = { source = format( "data:text/plain;base64,%s", base64encode(templatefile( "${path.module}/files/dhcp_nmconnection.tftpl", { iface = var.dhcp_iface ip_address = var.dhcp_server_ip_addr netmask = split("/", var.dhcp_range)[1] gateway = var.dhcp_gateway dns_server = var.dhcp_gateway } )) ) } } core_user = { name = "core" passwordHash = "$6$vDMAZf/yOO6mEbcs$6VE7WD8T9/PeotszMFxatOQxB/rFmLDWsNajg4sI0O47OikSuVpqPjkxRbzcueiXn6rBUY1ubCHlp0nnoZ1VI1" sshAuthorizedKeys = [ "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFQnLSYLGzUVmDMMGgEKCNgfAOkIuqhOMGGuvgskACum fmaury@2a01cb00142b3d00ee15f742996f2775.ipv6.abo.wanadoo.fr" ] } ignition_config = jsonencode({ ignition = { version = "3.4.0" } storage = { disks = [ local.data_disk, ] filesystems = concat( local.dhcp_filesystems, local.caddy_filesystems, local.sftp_filesystems, ) directories = concat( local.dhcp_directories, local.caddy_directories, local.sftp_directories, ) files = concat( [ local.hostname_file, local.network_config_file, ], module.sshd.files, local.dhcp_files, local.caddy_files, local.sftp_files, ) } systemd = { units = concat( local.dhcp_systemd_units, local.caddy_systemd_units, module.sshd.systemd_units, ) } passwd = { users = concat( [ local.core_user ], module.sshd.users, ) groups = module.sshd.groups } }) } resource "random_pet" "config_name" { length = 4 } locals { generated_ignition_config_file = "netboot_server_ignition_config_${random_pet.config_name.id}.ign" } resource "local_file" "api_token" { content = "Authorization: PVEAPIToken=${var.pve_api_token}" filename = "pve_api_token" file_permission = "0600" } resource "local_file" "netboot_server_ignition_config" { depends_on = [ local_file.api_token ] content = local.ignition_config filename = format("${path.module}/%s", local.generated_ignition_config_file) file_permission = "0644" # Download ISO to customize provisioner "local-exec" { command = <