What am I doing wrong?
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 ."
}
}
variable "ssh_username" {
description = "Unpriviledged user to create."
type = string
default = "mai-box"
}
variable "ssh_private_key_file" {
type = string
default = "~/.ssh/id_mai-box"
}
locals {
boot_command_qemu = [
"<enter><wait1.5m>",
"<leftCtrlOn><leftAltOn><f2><leftCtrlOff><leftAltOff><wait10s>",
"manjaro<enter><wait2s>",
"manjaro<enter><wait2s>",
"su -<enter><wait3s>",
"manjaro<enter><wait2s>",
"/usr/bin/curl -O http://{{ .HTTPIP }}:{{ .HTTPPort }}/enable-ssh.sh<enter><wait3s>",
"/usr/bin/curl -O http://{{ .HTTPIP }}:{{ .HTTPPort }}/id_mai-box<enter><wait3s>",
"/usr/bin/curl -O http://{{ .HTTPIP }}:{{ .HTTPPort }}/poweroff.timer<enter><wait3s>",
"/usr/bin/bash ./enable-ssh.sh<enter><wait15s>",
]
boot_command_virtualbox = [
"<enter><wait2.5m>",
"<leftCtrlOn><leftAltOn><f2><leftCtrlOff><leftAltOff><wait10s>",
"manjaro<enter><wait2s>",
"manjaro<enter><wait2s>",
"su -<enter><wait3s>",
"manjaro<enter><wait2s>",
"/usr/bin/curl -O http://{{ .HTTPIP }}:{{ .HTTPPort }}/enable-ssh.sh<enter><wait3s>",
"/usr/bin/curl -O http://{{ .HTTPIP }}:{{ .HTTPPort }}/poweroff.timer<enter><wait3s>",
"/usr/bin/bash ./enable-ssh.sh<enter><wait15s>",
]
iso_checksum = "file: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 "qemu" "main" {
accelerator = "kvm"
boot_command = "${local.boot_command_qemu}"
boot_wait = "2s"
communicator = "ssh"
cpus = 1
disk_compression = true
disk_image = true
disk_interface = "virtio"
disk_size = "4G"
format = "qcow2"
headless = "${var.headless}"
http_directory = "srv"
iso_checksum = "${local.iso_checksum}"
iso_url = "${local.iso_url}"
memory = 4096
net_device = "virtio-net"
output_directory = "output"
shutdown_command = " | sudo systemctl start poweroff.timer"
ssh_username = "${var.ssh_username}"
ssh_private_key_file = "${var.ssh_private_key_file}"
ssh_port = 22
ssh_timeout = "${var.ssh_timeout}"
vm_name = "${local.vm_name}.qcow2"
vnc_port_max = 5910
vnc_port_min = 5910
}
build {
name = "manjaro-arm-installer"
sources = ["source.qemu.main"]
provisioner "file" {
destination = "/tmp/"
source = "./files"
}
provisioner "shell" {
only = ["qemu.main"]
execute_command = "{{ .Vars }} COUNTRY=${var.country} sudo -E -S bash '{{ .Path }}'"
expect_disconnect = true
scripts = [
"scripts/configure-qemu.sh",
"scripts/partition-table-gpt.sh",
"scripts/partition-ext4-lbios.sh",
"scripts/setup.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"
}
}