Some checks failed
Tests / check (push) Failing after 39s
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
116 lines
2.7 KiB
HCL
116 lines
2.7 KiB
HCL
packer {
|
|
required_version = "= 1.16.2"
|
|
required_plugins {
|
|
qemu = {
|
|
source = "github.com/hashicorp/qemu"
|
|
version = "= 1.1.7"
|
|
}
|
|
}
|
|
}
|
|
|
|
variable "name" {
|
|
type = string
|
|
}
|
|
|
|
variable "family" {
|
|
type = string
|
|
validation {
|
|
condition = contains(["debian", "rocky"], var.family)
|
|
error_message = "La famille doit valoir debian ou rocky."
|
|
}
|
|
}
|
|
|
|
variable "image_url" {
|
|
type = string
|
|
}
|
|
|
|
variable "image_checksum" {
|
|
type = string
|
|
validation {
|
|
condition = can(regex("^sha(256:[0-9a-f]{64}|512:[0-9a-f]{128})$", var.image_checksum))
|
|
error_message = "La somme doit être de la forme sha256:<64 hex> ou sha512:<128 hex>."
|
|
}
|
|
}
|
|
|
|
variable "target_gib" {
|
|
type = number
|
|
}
|
|
|
|
variable "work_gib" {
|
|
type = number
|
|
default = 2
|
|
}
|
|
|
|
variable "accelerator" {
|
|
type = string
|
|
}
|
|
|
|
variable "cpu_model" {
|
|
type = string
|
|
}
|
|
|
|
variable "ssh_public_key" {
|
|
type = string
|
|
}
|
|
|
|
variable "ssh_private_key_file" {
|
|
type = string
|
|
}
|
|
|
|
variable "output_directory" {
|
|
type = string
|
|
}
|
|
|
|
source "qemu" "image" {
|
|
vm_name = var.name
|
|
iso_url = var.image_url
|
|
iso_checksum = var.image_checksum
|
|
disk_image = true
|
|
use_backing_file = true
|
|
skip_resize_disk = true
|
|
skip_compaction = true
|
|
format = "qcow2"
|
|
disk_interface = "virtio"
|
|
disk_additional_size = ["${var.target_gib}G", "${var.work_gib}G"]
|
|
disk_discard = "unmap"
|
|
disk_detect_zeroes = "unmap"
|
|
accelerator = var.accelerator
|
|
cpu_model = var.cpu_model
|
|
cpus = 2
|
|
memory = 2048
|
|
headless = true
|
|
output_directory = var.output_directory
|
|
cd_label = "cidata"
|
|
cd_content = {
|
|
"meta-data" = "instance-id: two-images-build\n"
|
|
"user-data" = templatefile("${path.root}/seed/user-data.pkrtpl", { key = var.ssh_public_key })
|
|
}
|
|
communicator = "ssh"
|
|
ssh_username = "build"
|
|
ssh_private_key_file = var.ssh_private_key_file
|
|
ssh_timeout = "60m"
|
|
shutdown_command = "sudo shutdown -P now"
|
|
}
|
|
|
|
build {
|
|
sources = ["source.qemu.image"]
|
|
|
|
provisioner "shell" {
|
|
execute_command = "sudo {{ .Vars }} bash '{{ .Path }}'"
|
|
environment_vars = [
|
|
"FAMILY=${var.family}",
|
|
"IMAGE_URL=${var.image_url}",
|
|
"IMAGE_CHECKSUM=${var.image_checksum}",
|
|
"TARGET_BYTES=${var.target_gib * 1073741824}",
|
|
"WORK_BYTES=${var.work_gib * 1073741824}",
|
|
]
|
|
scripts = [
|
|
"${path.root}/scripts/target.sh",
|
|
"${path.root}/scripts/two.sh",
|
|
"${path.root}/scripts/${var.family}.sh",
|
|
"${path.root}/scripts/clean.sh",
|
|
"${path.root}/scripts/check.sh",
|
|
"${path.root}/scripts/release.sh",
|
|
]
|
|
}
|
|
}
|