packer-proxmox/rocky-9.0/server.pkr.hcl
Robert Kaussow 352601029b
Some checks reported errors
continuous-integration/drone/push Build was killed
initial commit
2022-08-06 22:17:14 +02:00

87 lines
2.6 KiB
HCL

packer {
required_version = ">= 1.8.3"
required_plugins {
proxmox = {
version = ">= 1.0.8"
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_username = var.build_username
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
})
}
data_source_command = "inst.ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ks.cfg"
}
source "proxmox-iso" "rocky-linux-90" {
// Proxmox Settings
proxmox_url = "${var.proxmox_url}"
node = "${var.proxmox_node}"
username = "${var.proxmox_username}"
password = "${var.proxmox_password}"
// 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}"
network_adapters {
bridge = "${var.vm_network_adapter_bridge}"
model = "${var.vm_network_adapter_model}"
vlan_tag = "${var.vm_network_adapter_vlan_tag}"
}
disks {
disk_size = "${var.vm_disk_size}"
format = "${var.proxmox_storage_format}"
storage_pool = "${var.proxmox_storage_pool}"
storage_pool_type = "${var.proxmox_storage_pool_type}"
type = "scsi"
}
scsi_controller = "virtio-scsi-pci"
// Removable Media Settings
iso_file = "${var.proxmox_iso_pool}/${var.proxmox_iso_file}"
http_content = "${local.data_source_content}"
// 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 = "${var.build_username}"
ssh_password = "${var.build_password}"
ssh_port = "${var.communicator_port}"
ssh_timeout = "${var.communicator_timeout}"
template_description = "${var.template_description} on ${local.buildtime}"
template_name = "${var.template_name}"
unmount_iso = true
}
build {
sources = ["source.proxmox-iso.rocky-linux-90"]
provisioner "shell" {
execute_command = "echo '${var.build_password}' | {{.Vars}} sudo -E -S sh -eux '{{.Path}}'"
scripts = formatlist("${path.cwd}/%s", var.scripts)
remote_folder = "/home/${var.build_username}"
}
}