iac/packer/ubuntu-noble/ubuntu-noble.pkr.hcl

156 lines
5.1 KiB
HCL
Raw Permalink Normal View History

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
2024-11-02 01:50:25 -04:00
source "proxmox-clone" "ubuntu-server-noble" {
2024-07-31 23:45:46 -04:00
# 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
node = "pve2"
2024-08-01 21:36:12 -04:00
2024-11-02 01:50:25 -04:00
clone_vm_id = "8102"
2024-08-01 21:36:12 -04:00
2024-11-02 01:50:25 -04:00
vm_id = "9997"
vm_name = "ubuntu-noble-template"
template_description = "Ubuntu Server Noble"
2024-07-31 23:45:46 -04:00
# VM System Settings
qemu_agent = true
# VM Hard Disk Settings
scsi_controller = "virtio-scsi-pci"
disks {
2024-11-02 01:50:25 -04:00
disk_size = "5G"
2024-07-31 23:45:46 -04:00
format = "raw"
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-07-31 23:45:46 -04:00
ssh_username = "mafyuh"
2024-08-01 21:36:12 -04:00
# WSL Filesystem
2024-07-31 23:45:46 -04:00
ssh_private_key_file = "~/.ssh/id_rsa"
}
2024-07-31 23:45:46 -04:00
build {
2024-11-02 01:50:25 -04:00
name = "ubuntu-server-noble"
sources = ["source.proxmox-clone.ubuntu-server-noble"]
2024-07-31 23:45:46 -04:00
2024-08-01 21:36:12 -04:00
## Cleanup for re-template
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",
2024-11-02 01:50:25 -04:00
"sudo rm -f /var/lib/dbus/machine-id",
"sudo rm -f /var/lib/systemd/random-seed",
2024-07-31 23:45:46 -04:00
"sudo rm -f /etc/cloud/cloud.cfg.d/subiquity-disable-cloudinit-networking.cfg",
"sudo rm -f /etc/netplan/00-installer-config.yaml",
"sudo sync"
]
}
provisioner "file" {
source = "files/pve.cfg"
2024-07-31 23:45:46 -04:00
destination = "/tmp/pve.cfg"
}
provisioner "shell" {
inline = [ "sudo cp /tmp/pve.cfg /etc/cloud/cloud.cfg.d/pve.cfg" ]
}
2024-11-07 20:22:31 -05:00
provisioner "file" {
source = "files/daemon.json"
destination = "/tmp/daemon.json"
}
2024-11-02 01:50:25 -04:00
2024-07-31 23:45:46 -04:00
provisioner "shell" {
inline = [
2024-11-02 01:50:25 -04:00
# Install packages and add repositories
2024-11-07 20:22:31 -05:00
"wget https://github.com/fastfetch-cli/fastfetch/releases/download/2.29.0/fastfetch-linux-amd64.deb",
"sudo dpkg -i fastfetch-linux-amd64.deb",
"rm -f fastfetch-linux-amd64.deb",
2024-11-02 01:50:25 -04:00
"sudo apt-get update",
2024-11-07 20:22:31 -05:00
"sudo apt-get install -y ca-certificates curl gnupg lsb-release nfs-common net-tools zsh fzf",
2024-11-02 01:50:25 -04:00
# Change default shell to zsh
2024-09-21 18:58:16 -04:00
"sudo chsh -s $(which zsh) mafyuh",
2024-11-07 20:22:31 -05:00
# Install Docker & Loki Plugin
2024-07-31 23:45:46 -04:00
"curl -fsSL https://get.docker.com | sudo sh",
2024-11-07 20:22:31 -05:00
"sudo docker plugin install grafana/loki-docker-driver:latest --alias loki --grant-all-permissions",
"sudo mv /tmp/daemon.json /etc/docker/daemon.json",
# Set DNS
"sudo mkdir -p /etc/systemd/resolved.conf.d && echo '[Resolve]\nDNS=10.0.0.40' | sudo tee /etc/systemd/resolved.conf.d/dns_servers.conf",
2024-11-02 01:50:25 -04:00
# Install Oh My Zsh and plugins
2024-09-21 18:58:16 -04:00
"sh -c \"$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)\" --unattended",
"git clone https://github.com/zsh-users/zsh-syntax-highlighting.git $${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting",
"git clone https://github.com/zsh-users/zsh-autosuggestions.git $${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/zsh-autosuggestions",
"git clone https://github.com/zsh-users/zsh-history-substring-search.git $${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/zsh-history-substring-search",
"git clone https://github.com/MichaelAquilina/zsh-you-should-use.git $${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/you-should-use",
2024-11-02 01:50:25 -04:00
# Install Oh My Posh
2024-09-21 18:58:16 -04:00
"mkdir -p /home/mafyuh/.local/bin",
"curl -fsSL https://github.com/JanDeDobbeleer/oh-my-posh/releases/latest/download/posh-linux-amd64 -o /home/mafyuh/.local/bin/oh-my-posh",
"sudo chmod +x /home/mafyuh/.local/bin/oh-my-posh",
2024-11-02 01:50:25 -04:00
# Download posh theme locally
"mkdir -p /home/mafyuh/.oh-my-posh/themes",
"curl -fsSL https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/sonicboom_dark.omp.json -o /home/mafyuh/.oh-my-posh/themes/sonicboom_dark.omp.json",
# Setup Git
"git config --global user.name \"Mafyuh\"",
"git config --global user.email \"matt@mafyuh.com\"",
2024-11-07 20:22:31 -05:00
"sudo apt-get -y upgrade"
2024-07-31 23:45:46 -04:00
]
}
2024-09-21 18:58:16 -04:00
provisioner "file" {
source = "files/.zshrc"
destination = "~/.zshrc"
}
}