diff options
Diffstat (limited to 'openbsd.pkr.hcl')
| -rw-r--r-- | openbsd.pkr.hcl | 182 |
1 files changed, 0 insertions, 182 deletions
diff --git a/openbsd.pkr.hcl b/openbsd.pkr.hcl deleted file mode 100644 index bba0327..0000000 --- a/openbsd.pkr.hcl +++ /dev/null @@ -1,182 +0,0 @@ -packer { - required_plugins { - qemu = { source = "github.com/hashicorp/qemu", version = ">= 1.1.0" } - } -} - -variable "version" { - type = string - 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 "ssh_public_key" { - type = string - description = "Public SSH key to associate with the admin user for login" -} - -variable "ssh_private_key_file" { - type = string - description = "Private SSH key to associate with the admin user for login" -} - -variable "arch" { - type = string - validation { - condition = contains(["amd64", "arm64"], var.arch) - error_message = "The arch must be one of: amd64, arm64." - } -} - -variable "admin_user" { - type = string - description = "Username of the admin user on the VM" - default = "admin" -} - -variable "mirror" { - type = string - description = "URL basename for where to download the OpenBSD ISO." - default = "https://cdn.openbsd.org" - validation { - condition = can(regex("^(https?)://", var.mirror)) && !endswith(var.mirror, "/") - error_message = "URL must start with http(s):// and must not have a trailing slash." - } -} - -variable "hostname" { - type = string - description = "Hostname for the VM" - default = "openbsd-vm" -} - -variable "memory" { - type = number - description = "Memory to allocate to the VM in MB" - default = 4096 -} - -variable "disk_size" { - type = number - description = "Size of the disk in GB" - default = 16 -} - -locals { - version_short = replace(var.version, ".", "") - root_password = "temp" -} - -source "qemu" "openbsd-amd64" { - vm_name = "openbsd-${var.version}-amd64.qcow2" - iso_url = "${var.mirror}/pub/OpenBSD/${var.version}/${var.arch}/install${local.version_short}.iso" - iso_checksum = "file:${var.mirror}/pub/OpenBSD/${var.version}/${var.arch}/SHA256" - output_directory = "build" - qemu_binary = "qemu-system-x86_64" - machine_type = "q35" - cpu_model = "max" - accelerator = "tcg" - memory = var.memory - disk_interface = "virtio" - disk_size = "${var.disk_size}G" - disk_compression = true - format = "qcow2" - ssh_username = "root" - ssh_password = local.root_password - ssh_timeout = "30m" - - http_content = { - "/install.conf" = templatefile("${path.root}/templates/install.conf.pkrtpl.hcl", { - hostname = var.hostname - user = var.admin_user - ssh_key = var.ssh_public_key - root_password = local.root_password - mirror = var.mirror - version = var.version - version_short = local.version_short - arch = var.arch - }) - } - - boot_command = [ - "<wait>S<enter><wait>", - "set tty com0<enter><wait>", - "autoinstall<enter><wait>", - "http://{{ .HTTPIP }}:{{ .HTTPPort }}/install.conf<enter>", - ] - boot_wait = "20s" - shutdown_command = "shutdown -p now" - headless = false - qemuargs = [["-display", "cocoa"]] -} - -source "qemu" "openbsd-arm64" { - vm_name = "openbsd-${var.version}-aarch64.qcow2" - iso_url = "${var.mirror}/pub/OpenBSD/${var.version}/${var.arch}/install${local.version_short}.iso" - iso_checksum = "file:${var.mirror}/pub/OpenBSD/${var.version}/${var.arch}/SHA256" - output_directory = "build" - qemu_binary = "qemu-system-aarch64" - machine_type = "virt" - cpu_model = "host" - accelerator = "hvf" - memory = var.memory - disk_interface = "virtio" - disk_size = "${var.disk_size}G" - disk_compression = true - format = "qcow2" - ssh_username = "root" - ssh_password = local.root_password - ssh_timeout = "10m" - - http_content = { - "/install.conf" = templatefile("${path.root}/templates/install.conf.pkrtpl.hcl", { - hostname = var.hostname - user = var.admin_user - ssh_key = var.ssh_public_key - root_password = local.root_password - mirror = var.mirror - version = var.version - version_short = local.version_short - arch = var.arch - }) - } - - boot_command = [ - "<wait>S<enter><wait>", - "set tty com0<enter><wait>", - "autoinstall<enter><wait>", - "http://{{ .HTTPIP }}:{{ .HTTPPort }}/install.conf<enter>", - ] - boot_wait = "20s" - shutdown_command = "shutdown -p now" - use_default_display = true - headless = false - qemuargs = [ - ["-device", "qemu-xhci,id=xhci"], - ["-device", "usb-kbd,bus=xhci.0"], - ["-device", "virtio-gpu-pci"], - ["-display", "cocoa"], - ] - efi_firmware_code = "/opt/homebrew/share/qemu/edk2-aarch64-code.fd" - efi_firmware_vars = "./edk2-arm-vars.fd" -} - -build { - sources = ["source.qemu.openbsd-amd64", "source.qemu.openbsd-arm64"] - - provisioner "file" { - source = "configs/doas.conf" - destination = "/etc/doas.conf" - } - - provisioner "shell" { - script = "scripts/setup.sh" - environment_vars = ["ADMIN_USER=${var.admin_user}"] - } - - provisioner "shell" { - script = "scripts/harden-root.sh" - } -} |