Or does packer only skip downloading ISOs if the iso_url is set to a local file and there’s an ISO in packer_cache?
my.pkr.hcl
variable "country" {
type = string
default = "NL"
validation {
condition = length(var.country) == 2
error_message = "The country value must be two characters long."
}
}
variable "headless" {
type = bool
default = false
validation {
condition = can(var.headless)
error_message = "The headless value must exist."
}
}
variable "ssh_timeout" {
type = string
default = "20m"
validation {
condition = can(regex("[0-9]+[smh]", var.ssh_timeout))
error_message = "The ssh_timeout value must be a number followed by the letter s(econds), m(inutes), or h(ours)."
}
}
variable "write_zeros" {
type = string
default = true
validation {
condition = can(var.write_zeros)
error_message = "The write_zeros value must exist."
}
}
variable "iso_version" {
type = string
default = "22.08"
validation {
condition = can(regex("[0-9]+[.][0-9]+", var.iso_version))
error_message = "The iso_version value must be a valid semver x.x ."
}
}
locals {
boot_command_qemu = [
"<enter><wait45><wait45>",
"<leftCtrlOn><leftAltOn><f2><leftCtrlOff><leftAltOff><wait10>",
"manjaro<enter><wait2>",
"manjaro<enter><wait2>",
"su -<enter><wait3>",
"manjaro<enter><wait2>",
"/usr/bin/curl -O http://{{ .HTTPIP }}:{{ .HTTPPort }}/enable-ssh.sh<enter><wait3>",
"/usr/bin/curl -O http://{{ .HTTPIP }}:{{ .HTTPPort }}/poweroff.timer<enter><wait3>",
"/usr/bin/bash ./enable-ssh.sh<enter><wait15>",
]
boot_command_virtualbox = [
"<enter><wait90><wait90>",
"<leftCtrlOn><leftAltOn><f2><leftCtrlOff><leftAltOff><wait10>",
"manjaro<enter><wait2>",
"manjaro<enter><wait2>",
"su -<enter><wait3>",
"manjaro<enter><wait2>",
"/usr/bin/curl -O http://{{ .HTTPIP }}:{{ .HTTPPort }}/enable-ssh.sh<enter><wait3>",
"/usr/bin/curl -O http://{{ .HTTPIP }}:{{ .HTTPPort }}/poweroff.timer<enter><wait3>",
"/usr/bin/bash ./enable-ssh.sh<enter><wait15>",
]
iso_checksum = "https://github.com/manjaro-arm/generic-images/releases/download/${var.iso_version}/Manjaro-ARM-minimal-generic-${var.iso_version}.img.xz.sha1"
iso_url = "https://github.com/manjaro-arm/generic-images/releases/download/${var.iso_version}/Manjaro-ARM-minimal-generic-${var.iso_version}.img.xz"
name = "manjaro-arm-installer"
vm_name = "manjaro-arm-installer"
}
source "virtualbox-iso" "main" {
boot_command = "${local.boot_command_virtualbox}"
boot_wait = "2s"
communicator = "ssh"
cpus = 1
disk_size = 4096
format = "ovf"
guest_additions_mode = "disable"
guest_os_type = "Manjaro"
hard_drive_interface = "sata"
headless = "${var.headless}"
http_directory = "srv"
iso_checksum = "file:${local.iso_checksum}"
iso_url = "${local.iso_url}"
memory = 2048
output_directory = "output"
shutdown_command = "sudo systemctl start poweroff.timer"
ssh_username = "vagrant"
ssh_password = "vagrant"
ssh_port = 22
ssh_timeout = "${var.ssh_timeout}"
vm_name = "${local.vm_name}"
}
build {
name = "manjaro-arm-installer"
sources = ["source.virtualbox-iso.main"]
provisioner "file" {
destination = "/tmp/"
source = "./files"
}
provisioner "shell" {
only = ["virtualbox-iso.main"]
execute_command = "{{ .Vars }} sudo -E -S bash '{{ .Path }}'"
script = "scripts/install-virtualbox.sh"
}
provisioner "shell" {
only = ["virtualbox-iso.main"]
execute_command = "{{ .Vars }} COUNTRY=${var.country} sudo -E -S bash '{{ .Path }}'"
expect_disconnect = true
script = "scripts/install-base-ext4-mbr-lbios.sh"
}
provisioner "shell" {
execute_command = "{{ .Vars }} WRITE_ZEROS=${var.write_zeros} sudo -E -S bash '{{ .Path }}'"
script = "scripts/cleanup.sh"
}
post-processor "vagrant" {
keep_input_artifact = true
output = "output/${local.vm_name}_${source.type}_${source.name}-${formatdate("YYYY-MM", timestamp())}.box"
vagrantfile_template = "templates/vagrantfile.tpl"
}
}