Skip to content

Instantly share code, notes, and snippets.

@lsjostro
Created November 24, 2023 11:01
Show Gist options
  • Save lsjostro/7b360848bfc61b3acad32112679d8e84 to your computer and use it in GitHub Desktop.
Save lsjostro/7b360848bfc61b3acad32112679d8e84 to your computer and use it in GitHub Desktop.
packer {
required_plugins {
proxmox-iso = {
version = ">= 1.1.5"
source = "github.com/hashicorp/proxmox"
}
}
}
variable "pve_node" {
type = string
default = "pve"
}
variable "iso_storage_pool" {
type = string
default = "local-btrfs"
}
variable "storage_pool" {
type = string
default = "local-btrfs"
}
variable "disk_size" {
type = string
default = "32G"
}
variable "os" {
type = string
default = "debian"
}
variable "version" {
type = string
default = "12"
}
variable "image_url" {
type = string
default = "https://cloud.debian.org/images/cloud/bookworm/daily/latest/debian-12-generic-amd64-daily.qcow2"
}
variable "image_format" {
type = string
default = "qcow2"
}
variable "uncmp_cmd" {
type = string
default = "cat"
}
locals {
password = "packer"
}
source "proxmox-iso" "img" {
template_name = "${var.os}-${var.version}-${formatdate("YYYYMMDD", timestamp())}"
template_description = "${var.os} ${var.version} template ${formatdate("YYYY-MM-DD", timestamp())}"
iso_url = "https://dl-cdn.alpinelinux.org/alpine/v3.18/releases/x86_64/alpine-virt-3.18.4-x86_64.iso"
iso_checksum = "sha256:24d79bc148c05a864c2914dfa41a6ffbf808973e44de88c7700d30b4517965b2"
// iso_download_pve = true
unmount_iso = true
iso_storage_pool = var.iso_storage_pool
node = var.pve_node
boot_command = [
"root<enter>",
"echo root:${local.password} | chpasswd<enter>",
# "ip a add ${var.ip_address} dev eth0 && ip link set eth0 up && ip r add default via ${var.ip_gateway}<enter>",
"ip link set eth0 up && udhcpc -i eth0<enter>",
"setup-dns 1.1.1.1<enter>",
"setup-apkrepos -c1<enter>",
"apk add openssh openssh-server-pam qemu-guest-agent qemu-img xz zstd curl<enter>",
"echo 'PermitRootLogin yes' >> /etc/ssh/sshd_config<enter>",
"service sshd start && service qemu-guest-agent start<enter>",
]
boot_wait = "15s"
insecure_skip_tls_verify = true
qemu_agent = true
task_timeout = "10m"
ssh_username = "root"
ssh_password = "packer"
cores = 4
memory = 2048
cpu_type = "host"
scsi_controller = "virtio-scsi-single"
machine = "q35"
cloud_init = true
cloud_init_storage_pool = var.storage_pool
network_adapters {
model = "virtio"
bridge = "vmbr0"
}
disks {
type = "scsi"
storage_pool = var.storage_pool
disk_size = var.disk_size
io_thread = true
}
}
build {
sources = ["source.proxmox-iso.img"]
provisioner "shell" {
inline = [
"curl -sL ${var.image_url} | ${var.uncmp_cmd} > /tmp/img",
"qemu-img convert -f ${var.image_format} /tmp/img -O raw /dev/sda"
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment