packer-proxmox/rocky-9/server.pkr.hcl

94 lines
2.7 KiB
HCL
Raw Normal View History

2022-08-06 20:17:14 +00:00
packer {
required_version = ">= 1.8.3"
required_plugins {
proxmox = {
version = "1.1.6"
2022-08-06 20:17:14 +00:00
source = "github.com/hashicorp/proxmox"
}
}
}
locals {
buildtime = formatdate("YYYY-MM-DD hh:mm ZZZ", timestamp())
data_source_content = {
"/ks.cfg" = templatefile("${abspath(path.root)}/data/init.ks.pkrtpl.hcl", {
build_password_encrypted = var.build_password_encrypted
vm_guest_os_language = var.vm_guest_os_language
vm_guest_os_keyboard = var.vm_guest_os_keyboard
vm_guest_os_timezone = var.vm_guest_os_timezone
files_proxmox_default_init = file("${abspath(path.root)}/data/files/90-proxmox.cfg")
files_proxmox_init = file("${abspath(path.root)}/data/files/93-proxmox.cfg")
2022-08-06 20:17:14 +00:00
})
}
data_source_command = "inst.ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ks.cfg"
}
source "proxmox-iso" "rocky-linux-9" {
2022-08-06 20:17:14 +00:00
// Proxmox Settings
proxmox_url = "${var.proxmox_url}"
node = "${var.proxmox_node}"
username = "${var.proxmox_username}"
token = "${var.proxmox_token}"
2022-08-06 20:17:14 +00:00
// Virtual Machine Settings
vm_id = "${var.vm_id}"
cores = "${var.vm_cpu_cores}"
sockets = "${var.vm_cpu_sockets}"
cpu_type = "${var.vm_cpu_type}"
memory = "${var.vm_mem_size}"
os = "${var.vm_os_type}"
2022-08-10 14:01:24 +00:00
cloud_init = "${var.vm_cloud_init}"
cloud_init_storage_pool = "${var.vm_cloud_init_storage_pool}"
qemu_agent = "${var.vm_qemu_agent}"
2022-08-06 20:17:14 +00:00
network_adapters {
bridge = "${var.vm_network_adapter_bridge}"
model = "${var.vm_network_adapter_model}"
vlan_tag = "${var.vm_network_adapter_vlan_tag}"
}
2022-08-10 14:01:24 +00:00
2022-08-06 20:17:14 +00:00
disks {
disk_size = "${var.vm_disk_size}"
format = "${var.proxmox_storage_format}"
storage_pool = "${var.proxmox_storage_pool}"
type = "scsi"
2024-01-17 19:46:30 +00:00
io_thread = false
discard = true
2022-08-06 20:17:14 +00:00
}
2022-08-10 14:01:24 +00:00
2022-08-06 20:17:14 +00:00
scsi_controller = "virtio-scsi-pci"
// Removable Media Settings
iso_file = "${var.proxmox_iso_pool}/${var.proxmox_iso_file}"
http_content = "${local.data_source_content}"
http_interface = "${var.http_interface}"
2022-08-06 20:17:14 +00:00
// Boot and Provisioning Settings
boot_wait = "10s"
boot_command = [
"up",
"<tab><wait>",
" ${local.data_source_command}<wait><enter>"
]
// Communicator Settings and Credentials
communicator = "ssh"
ssh_username = "root"
2022-08-06 20:17:14 +00:00
ssh_password = "${var.build_password}"
ssh_timeout = "${var.communicator_timeout}"
template_description = "${var.proxmox_template_description} on ${local.buildtime}"
template_name = "${var.proxmox_template_name}"
unmount_iso = true
2022-08-06 20:17:14 +00:00
}
build {
sources = ["source.proxmox-iso.rocky-linux-9"]
2022-08-06 20:17:14 +00:00
provisioner "shell" {
scripts = formatlist("${path.cwd}/%s", var.build_scripts)
remote_folder = "/root"
2022-08-06 20:17:14 +00:00
}
}