1
0
IaC/zz_archived/packer/libvirt/arch/arch-minimal.build.pkr.hcl

150 lines
3.4 KiB
HCL
Raw Normal View History

2022-10-02 22:19:24 -04:00
# -------------------------------------------------------------------------
# Name: vm-libvirt-arch-minimal
# Desc: Create a minimal Arch Linux VM install on a libvirt/kvm hypervisor.
# -------------------------------------------------------------------------
#--------------------
# Requirements block.
#--------------------
packer {
required_plugins {
libvirt = {
version = ">= 0.3.4"
source = "github.com/thomasklein94/libvirt"
}
}
}
# ----------------
# Variables block.
# ----------------
data "http" "image_checksum" {
url = var.checksum_url
}
locals {
2022-10-03 09:47:03 -04:00
image_checksum = split(" ",data.http.image_checksum.body)[0]
libvirt_uri = "qemu+ssh://${var.host_ssh_user}@${var.host_ssh_address}/system?keyfile=${var.host_ssh_private_key}&no_verify=1"
2022-10-02 22:19:24 -04:00
nvram_path = "${var.nvram_path_base}/${var.guest_hostname}_VARS.fd"
cidata_name = "${var.volume_name}_cidata"
}
#---------------
# Sources block.
#---------------
source "libvirt" "arch-minimal" {
libvirt_uri = local.libvirt_uri
domain_name = var.guest_hostname
vcpu = var.cpu_count
memory = var.memory
boot_devices = ["hd"]
shutdown_mode = "guest"
domain_type = var.domain_type
arch = var.arch
chipset = var.chipset
loader_type = var.loader_type
loader_path = var.loader_path
2022-10-03 09:47:03 -04:00
// nvram_template = var.nvram_template
// nvram_path = local.nvram_path
nvram_template = local.nvram_path
nvram_path = var.nvram_template
2022-10-03 07:11:25 -04:00
secure_boot = var.secure_boot
2022-10-02 22:19:24 -04:00
volume {
alias = "artifact"
2022-10-02 22:30:22 -04:00
name = var.volume_name
2022-10-02 22:19:24 -04:00
pool = var.volume_pool
readonly = false
target_dev = "vda"
bus = "virtio"
format = "qcow2"
size = "2G"
capacity = var.volume_capacity
source {
type = "external"
urls = [var.image_url]
checksum = local.image_checksum
2022-10-03 09:47:03 -04:00
// checksum = "f237ada9ba61431f6aebb066d2b3f0b5b432ea21da6034d98248725df1417545"
2022-10-02 22:19:24 -04:00
}
}
volume {
alias = "cidata"
name = local.cidata_name
pool = var.volume_pool
readonly = true
source {
type = "cloud-init"
meta_data = jsonencode({
2022-10-03 09:47:03 -04:00
"instance-id" = "${var.guest_hostname}"
"hostname" = "${var.guest_hostname}"
2022-10-02 22:19:24 -04:00
})
user_data = format("#cloud-config\n%s", jsonencode({
2022-10-03 09:47:03 -04:00
"packages" = [
2022-10-02 22:19:24 -04:00
"qemu-guest-agent",
"ufw"
]
2022-10-03 09:47:03 -04:00
"runcmd" = [
2022-10-02 22:19:24 -04:00
["systemctl", "enable", "--now", "qemu-guest-agent"],
["ufw", "enable"],
2022-10-03 09:47:03 -04:00
["ufw", "allow", "from", "${var.ssh_source}", "to", "port", "22", "proto", "tcp"],
2022-10-02 22:19:24 -04:00
["systemctl", "enable", "--now", "ufw"]
]
}))
network_config = jsonencode({
2022-10-03 07:11:25 -04:00
renderer = "networkd"
2022-10-02 22:19:24 -04:00
version = 2
ethernets = {
2022-10-03 07:11:25 -04:00
eth0 = {
2022-10-02 22:19:24 -04:00
match = {
name = "en*"
}
2022-10-03 07:11:25 -04:00
dhcp4 = false
2022-10-03 09:47:03 -04:00
addresses = ["${var.network_address}"]
gateway4 = "${var.network_gateway}"
2022-10-03 07:11:25 -04:00
nameservers = {
2022-10-03 09:47:03 -04:00
addresses = ["${var.network_nameserver}"]
search = ["${var.network_domain}"]
2022-10-03 07:11:25 -04:00
}
2022-10-02 22:19:24 -04:00
}
}
})
}
}
artifact_volume_alias = "artifact"
network_interface {
type = "bridge"
bridge = var.bridge_name
model = "virtio"
alias = "default-network"
}
network_address_source = "agent"
graphics {
2022-10-03 09:47:03 -04:00
type = "vnc"
port = 5902
2022-10-02 22:19:24 -04:00
}
communicator {
2022-10-03 09:47:03 -04:00
ssh_username = var.guest_ssh_user
ssh_port = var.guest_ssh_port
ssh_private_key_file = var.guest_ssh_private_key
2022-10-02 22:19:24 -04:00
}
communicator_interface = "default-network"
}
#-------------
# Build block.
#-------------
build {
sources = ["source.libvirt.arch-minimal"]
}