2024-07-31 23:45:46 -04:00
|
|
|
packer {
|
|
|
|
required_plugins {
|
|
|
|
name = {
|
|
|
|
version = "~> 1"
|
|
|
|
source = "github.com/hashicorp/proxmox"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
variable "proxmox_api_url" {
|
|
|
|
type = string
|
|
|
|
}
|
|
|
|
|
|
|
|
variable "proxmox_api_token_id" {
|
|
|
|
type = string
|
|
|
|
}
|
|
|
|
|
|
|
|
variable "proxmox_api_token_secret" {
|
|
|
|
type = string
|
|
|
|
sensitive = true
|
|
|
|
}
|
|
|
|
|
|
|
|
# Resource Definiation for the VM Template
|
|
|
|
source "proxmox-clone" "ubuntu-server-jammy" {
|
|
|
|
|
|
|
|
# Proxmox Connection Settings
|
|
|
|
proxmox_url = "${var.proxmox_api_url}"
|
|
|
|
username = "${var.proxmox_api_token_id}"
|
|
|
|
token = "${var.proxmox_api_token_secret}"
|
|
|
|
insecure_skip_tls_verify = true
|
|
|
|
|
|
|
|
# VM General Settings
|
2024-08-01 00:33:14 -04:00
|
|
|
node = "pve2"
|
2024-07-31 23:45:46 -04:00
|
|
|
clone_vm_id = "8101"
|
|
|
|
vm_id = "9636"
|
|
|
|
vm_name = "ubuntu-server-jammy"
|
|
|
|
template_description = "Ubuntu Server jammy Image"
|
|
|
|
|
|
|
|
# VM System Settings
|
|
|
|
qemu_agent = true
|
|
|
|
|
|
|
|
# VM Hard Disk Settings
|
|
|
|
scsi_controller = "virtio-scsi-pci"
|
|
|
|
|
|
|
|
disks {
|
|
|
|
disk_size = "5G"
|
|
|
|
format = "raw"
|
2024-08-01 00:33:14 -04:00
|
|
|
storage_pool = "Fast500Gb"
|
2024-07-31 23:45:46 -04:00
|
|
|
type = "virtio"
|
|
|
|
}
|
|
|
|
|
|
|
|
# VM CPU Settings
|
|
|
|
cores = "2"
|
|
|
|
cpu_type = "x86-64-v2-AES"
|
|
|
|
|
|
|
|
# VM Memory Settings
|
|
|
|
memory = "2048"
|
|
|
|
|
|
|
|
# VM Network Settings
|
|
|
|
network_adapters {
|
|
|
|
model = "virtio"
|
|
|
|
bridge = "vmbr0"
|
|
|
|
firewall = "false"
|
2024-08-01 00:33:14 -04:00
|
|
|
}
|
|
|
|
|
2024-07-31 23:45:46 -04:00
|
|
|
|
|
|
|
ssh_username = "mafyuh"
|
|
|
|
ssh_private_key_file = "~/.ssh/id_rsa"
|
|
|
|
}
|
|
|
|
|
2024-08-01 00:33:14 -04:00
|
|
|
|
2024-07-31 23:45:46 -04:00
|
|
|
build {
|
|
|
|
|
|
|
|
name = "ubuntu-server-jammy"
|
|
|
|
sources = ["source.proxmox-clone.ubuntu-server-jammy"]
|
|
|
|
|
2024-08-01 00:33:14 -04:00
|
|
|
|
2024-07-31 23:45:46 -04:00
|
|
|
provisioner "shell" {
|
|
|
|
inline = [
|
|
|
|
"while [ ! -f /var/lib/cloud/instance/boot-finished ]; do echo 'Waiting for cloud-init...'; sleep 1; done",
|
|
|
|
"sudo rm /etc/ssh/ssh_host_*",
|
|
|
|
"sudo truncate -s 0 /etc/machine-id",
|
|
|
|
"sudo apt -y autoremove --purge",
|
|
|
|
"sudo apt -y clean",
|
|
|
|
"sudo apt -y autoclean",
|
|
|
|
"sudo cloud-init clean",
|
|
|
|
"sudo rm -f /etc/cloud/cloud.cfg.d/subiquity-disable-cloudinit-networking.cfg",
|
|
|
|
"sudo rm -f /etc/netplan/00-installer-config.yaml",
|
|
|
|
"sudo sync"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
2024-08-01 00:33:14 -04:00
|
|
|
|
2024-07-31 23:45:46 -04:00
|
|
|
provisioner "file" {
|
2024-08-01 00:33:14 -04:00
|
|
|
source = "files/pve.cfg"
|
2024-07-31 23:45:46 -04:00
|
|
|
destination = "/tmp/pve.cfg"
|
|
|
|
}
|
|
|
|
|
2024-08-01 00:33:14 -04:00
|
|
|
|
2024-07-31 23:45:46 -04:00
|
|
|
provisioner "shell" {
|
|
|
|
inline = [ "sudo cp /tmp/pve.cfg /etc/cloud/cloud.cfg.d/pve.cfg" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
# Provisioning the VM Template with Docker Installation #4
|
|
|
|
provisioner "shell" {
|
|
|
|
inline = [
|
|
|
|
"sudo apt-get install -y ca-certificates curl gnupg lsb-release nfs-common qemu-guest-agent net-tools",
|
|
|
|
"curl -fsSL https://get.docker.com | sudo sh",
|
|
|
|
"echo \"alias dcu='docker compose up -d'\" >> ~/.bashrc",
|
2024-08-01 00:33:14 -04:00
|
|
|
"echo \"alias dcd='docker compose down'\" >> ~/.bashrc",
|
|
|
|
"git config --global user.name \"Mafyuh\"",
|
|
|
|
"git config --global user.email \"matt@mafyuh.com\"",
|
2024-07-31 23:45:46 -04:00
|
|
|
"sudo apt-get -y update"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|