packer { required_version = ">= 1.8.3" required_plugins { hcloud = { version = " 1.0.5" source = "github.com/hashicorp/hcloud" } } } locals { data_source_content = templatefile("${abspath(path.root)}/data/init.ks.pkrtpl.hcl", { build_password_encrypted = var.build_password_encrypted vm_guest_os_language = var.vm_guest_os_language vm_guest_os_keyboard = var.vm_guest_os_keyboard vm_guest_os_timezone = var.vm_guest_os_timezone hcloud_mirror = var.hcloud_mirror files_hcloud_metadata = file("${abspath(path.root)}/data/files/hcloud-metadata") files_hcloud_ssh_keys_service = file("${abspath(path.root)}/data/files/hcloud-ssh-keys.service") files_hetznercloud_default_init = file("${abspath(path.root)}/data/files/90-hetznercloud.cfg") files_hetznercloud_ds_init = file("${abspath(path.root)}/data/files/92-hetznercloud-ds.cfg") files_hetznercloud_init = file("${abspath(path.root)}/data/files/93-hetznercloud.cfg") }) build_id = "${uuidv4()}" build_labels = { "os" = "rockylinux" "os/release" = "9" "packer.io/build.time" = "{{ timestamp }}" "packer.io/build.id" = "${local.build_id}" "packer.io/version" = "{{ packer_version }}" } } source "hcloud" "rocky-linux-9" { // Hetzner Cloud Settings image = "rocky-9" rescue = "linux64" token = "${var.hcloud_token}" // Virtual Machine Settings location = "${var.hcloud_location}" server_type = "${var.hcloud_server_type}" server_name = "${var.hcloud_server_name}" // Communicator Settings and Credentials ssh_username = "root" temporary_key_pair_type = "ed25519" snapshot_name = "${var.hcloud_snapshot_name}-{{ timestamp }}" snapshot_labels = local.build_labels } build { sources = ["source.hcloud.rocky-linux-9"] provisioner "file" { destination = "/root/ks.cfg" content = "${local.data_source_content}" } provisioner "file" { destination = "/root/prepare-kickstart.sh" content = "${local.data_source_content}" } provisioner "shell" { scripts = formatlist("${path.cwd}/%s", var.build_scripts) remote_folder = "/root" start_retry_timeout = "15m" expect_disconnect = true environment_vars = [ "BUILD_MIRROR=${var.hcloud_mirror}", ] } }