base-image/arch.pkr.hcl

119 lines
2.6 KiB
HCL

variable "cpus" {
type = number
default = 2
}
variable "memory" {
type = number
default = 1024
}
variable "disk_size" {
type = string
default = "3G"
}
variable "iso_url" {
type = string
default = "https://mirrors.edge.kernel.org/archlinux/iso/latest/archlinux-x86_64.iso"
}
variable "iso_checksum" {
type = string
default = "file:https://mirrors.edge.kernel.org/archlinux/iso/latest/sha256sums.txt"
}
variable "ssh_username" {
type = string
default = "root"
}
variable "ssh_password" {
type = string
default = "password"
}
source "qemu" "arch" {
headless = true
accelerator = "kvm"
vm_name = "arch.img"
http_directory = "http"
output_directory = "output"
cpus = var.cpus
memory = var.memory
disk_size = var.disk_size
format = "raw"
iso_url = var.iso_url
iso_checksum = var.iso_checksum
iso_target_path = "cache/arch.iso"
boot_wait = "2s"
boot_key_interval = "25ms"
boot_command = [
"<enter>",
"<wait30s>",
"echo '${var.ssh_username}:${var.ssh_password}' | chpasswd<enter>"
]
ssh_username = var.ssh_username
ssh_password = var.ssh_password
shutdown_command = "sudo -S shutdown -P now"
}
build {
sources = ["source.qemu.arch"]
provisioner "shell" {
pause_before = "5s"
scripts = [
"${path.root}/scripts/partition_disk.sh",
"${path.root}/scripts/install_system.sh",
"${path.root}/scripts/timezone_and_locale.sh",
"${path.root}/scripts/add_deploy_user.sh",
]
}
provisioner "file" {
source = "files/99-dhcp-wildcard.network"
destination = "/mnt/etc/systemd/network/99-dhcp-wildcard.network"
}
provisioner "file" {
source = "files/grow-root"
destination = "/usr/local/sbin/grow-root"
}
provisioner "shell" {
inline = ["chmod +x /usr/local/sbin/grow-root"]
}
provisioner "file" {
source = "files/grow-root.service"
destination = "/etc/systemd/system/grow-root.service"
}
provisioner "shell" {
pause_before = "10s"
scripts = [
"${path.root}/scripts/enable_services.sh",
"${path.root}/scripts/install_bootloader.sh",
"${path.root}/scripts/truncate_empty_space.sh",
"${path.root}/scripts/finalization.sh"
]
}
post-processor "checksum" {
checksum_types = ["sha256"]
keep_input_artifact = true
}
# Validate that the image is good
// post-processor "shell-local" {
// inline = ["qemu-system-x86_64 -drive file=output/arch.img -m 1024"]
// }
}