From 6af7d3015167983b50a9d2a14fc654f328e0a3bb Mon Sep 17 00:00:00 2001 From: Matt Reeves Date: Sat, 14 Sep 2024 23:16:21 -0400 Subject: [PATCH] add ubu and packer template for node 1 --- packer/ubuntu-jammy/ubuntu-jammy2.pkr.hcl | 119 ++++++++++++++++++++++ terraform/ubu.tf | 71 +++++++++++++ terraform/vars.tf | 4 + 3 files changed, 194 insertions(+) create mode 100644 packer/ubuntu-jammy/ubuntu-jammy2.pkr.hcl create mode 100644 terraform/ubu.tf diff --git a/packer/ubuntu-jammy/ubuntu-jammy2.pkr.hcl b/packer/ubuntu-jammy/ubuntu-jammy2.pkr.hcl new file mode 100644 index 0000000..3d40ae2 --- /dev/null +++ b/packer/ubuntu-jammy/ubuntu-jammy2.pkr.hcl @@ -0,0 +1,119 @@ +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-jammy2" { + + # 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 = "prox" + + clone_vm_id = "8100" + + vm_id = "9998" + vm_name = "ubuntu-server-jammy2" + template_description = "Custom Ubuntu Server see https://git.mafyuh.dev/mafyuh/iac/src/branch/main/packer/ubuntu-jammy/ubuntu-jammy2.pkr.hcl" + + # VM System Settings + qemu_agent = true + + # VM Hard Disk Settings + scsi_controller = "virtio-scsi-pci" + + disks { + disk_size = "4G" + format = "raw" + storage_pool = "Fast2Tb" + 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" + } + + + ssh_username = "mafyuh" + # WSL Filesystem + ssh_private_key_file = "~/.ssh/id_rsa" +} + + +build { + + name = "ubuntu-server-jammy2" + sources = ["source.proxmox-clone.ubuntu-server-jammy2"] + + ## Cleanup for re-template + 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" + ] + } + + + provisioner "file" { + source = "files/pve.cfg" + destination = "/tmp/pve.cfg" + } + + + provisioner "shell" { + inline = [ "sudo cp /tmp/pve.cfg /etc/cloud/cloud.cfg.d/pve.cfg" ] + } + + # Install Commonly Used Things - add alias's - set git config + 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", + "echo \"alias dcd='docker compose down'\" >> ~/.bashrc", + "git config --global user.name \"Mafyuh\"", + "git config --global user.email \"matt@mafyuh.com\"", + "sudo apt-get -y update" + ] + } +} \ No newline at end of file diff --git a/terraform/ubu.tf b/terraform/ubu.tf new file mode 100644 index 0000000..94549ca --- /dev/null +++ b/terraform/ubu.tf @@ -0,0 +1,71 @@ +resource "proxmox_virtual_environment_vm" "Ubu" { + + # VM General Settings + node_name = "prox" + vm_id = 5000 + name = "Ubu" + description = "My attempt to move things to 1 VM" + tags = ["tofu", "ubuntu-22", "auto-homelab-repo", "infrastructure"] + + agent { + enabled = true # read 'Qemu guest agent' section, change to true only when ready + } + + clone { + vm_id = 9998 + } + + # VM CPU Settings + cpu { + cores = 2 + type = "host" + architecture = "x86_64" + } + + # VM Memory Settings + memory { + dedicated = 6144 + } + + # VM Network Settings + network_device { + bridge = "vmbr0" + vlan_id = 1 + } + + # VM Disk Settings + disk { + datastore_id = "Fast2Tb" + size = 120 + interface = "scsi0" + } + + vga { + type = "serial0" + } + + initialization { + ip_config { + ipv4 { + address = var.ubu_ip_address + gateway = var.vlan_gateway + } + } + + user_data_file_id = proxmox_virtual_environment_file.cloud_config.id + } + + lifecycle { + ignore_changes = [ + initialization[0].user_account[0].keys, + initialization[0].user_account[0].password, + initialization[0].user_account[0].username, + initialization[0].user_data_file_id + ] + } + +} + +output "vm_ipv4_address" { + value = proxmox_virtual_environment_vm.Ubu.ipv4_addresses[1][0] +} \ No newline at end of file diff --git a/terraform/vars.tf b/terraform/vars.tf index cb9fecd..94ffaca 100644 --- a/terraform/vars.tf +++ b/terraform/vars.tf @@ -52,4 +52,8 @@ variable "kasm_ip" { variable "kasm_ssh_ip" { type = string +} + +variable "ubu_ip_address" { + type = string } \ No newline at end of file