packer-hcloud/rocky-9/server.pkr.hcl
Robert Kaussow 66128a311c
Some checks failed
ci/woodpecker/push/docs Pipeline was successful
ci/woodpecker/push/test Pipeline failed
fix packer validate
2024-01-17 22:12:02 +01:00

76 lines
2.5 KiB
HCL

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")
files_hcloud_nm_eth0 = file("${abspath(path.root)}/data/files/nm-eth0.conf")
})
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}",
]
}
}