diff options
Diffstat (limited to 'hcloud-snapshot')
| -rw-r--r-- | hcloud-snapshot/main.pkr.hcl | 22 | ||||
| -rw-r--r-- | hcloud-snapshot/snapshot.pkr.hcl | 10 | ||||
| -rw-r--r-- | hcloud-snapshot/variables.pkr.hcl | 33 |
3 files changed, 65 insertions, 0 deletions
diff --git a/hcloud-snapshot/main.pkr.hcl b/hcloud-snapshot/main.pkr.hcl new file mode 100644 index 0000000..920eeae --- /dev/null +++ b/hcloud-snapshot/main.pkr.hcl @@ -0,0 +1,22 @@ +packer { + required_plugins { + hcloud = { source = "github.com/hetznercloud/hcloud", version = "~> 1" } + } +} + +build { + sources = ["source.hcloud.openbsd"] + + provisioner "file" { + source = var.image_path + destination = "/tmp/openbsd.raw.zst" + } + + provisioner "shell" { + inline = [ + "which zstd || apt-get install --assume-yes zstd", + "zstd --decompress --stdout /tmp/openbsd.raw.zst | dd of=/dev/sda bs=4M status=progress", + "sync", + ] + } +} diff --git a/hcloud-snapshot/snapshot.pkr.hcl b/hcloud-snapshot/snapshot.pkr.hcl new file mode 100644 index 0000000..d8834c8 --- /dev/null +++ b/hcloud-snapshot/snapshot.pkr.hcl @@ -0,0 +1,10 @@ +source "hcloud" "openbsd" { + token = var.hcloud_token + rescue = "linux64" + image = "debian-13" + server_type = "cx23" + location = "nbg1" + ssh_username = "root" + ssh_keys = [var.ssh_key] + snapshot_name = "openbsd-${var.version}-${var.arch}-golden" +} diff --git a/hcloud-snapshot/variables.pkr.hcl b/hcloud-snapshot/variables.pkr.hcl new file mode 100644 index 0000000..a02e433 --- /dev/null +++ b/hcloud-snapshot/variables.pkr.hcl @@ -0,0 +1,33 @@ +variable "hcloud_token" { + type = string + description = "Hetnzer API token" + sensitive = true +} + +variable "image_path" { + type = string + description = "Path to the built OpenBSD raw zstd compressed image" +} + +variable "version" { + type = string + description = "Version of OpenBSD to build" + validation { + condition = can(regex("^\\d\\.\\d$", var.version)) + error_message = "The version must be a single-digit followed by a period followed by another single digit." + } +} + +variable "arch" { + type = string + validation { + condition = contains(["amd64", "arm64"], var.arch) + error_message = "The arch must be one of: amd64, arm64." + } +} + +variable "ssh_key" { + type = string + description = "SSH key name in Hetzner to add to the image on launch" +} + |