diff --git a/.gitignore b/.gitignore index bb05696..29ffce3 100644 --- a/.gitignore +++ b/.gitignore @@ -42,3 +42,5 @@ terraform.rc ## Kubernetes /kubernetes/cluster/apps/staging +## Packer +credentials.pkr.hcl diff --git a/packer/ubuntu-noble/files/pve.cfg b/packer/ubuntu-noble/files/pve.cfg new file mode 100644 index 0000000..a78672c --- /dev/null +++ b/packer/ubuntu-noble/files/pve.cfg @@ -0,0 +1 @@ +datasource_list: [ConfigDrive, NoCloud] \ No newline at end of file diff --git a/packer/ubuntu-noble/ubuntu-jammy.pkr.hcl b/packer/ubuntu-noble/ubuntu-jammy.pkr.hcl new file mode 100644 index 0000000..cfe46fa --- /dev/null +++ b/packer/ubuntu-noble/ubuntu-jammy.pkr.hcl @@ -0,0 +1,116 @@ +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 + node = "prox" + 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" + 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" + } + + # VM Cloud-Init Settings + cloud_init = true + cloud_init_storage_pool = "local-lvm" + + ssh_username = "mafyuh" + ssh_private_key_file = "~/.ssh/id_rsa" +} + +# Build Definition to create the VM Template +build { + + name = "ubuntu-server-jammy" + sources = ["source.proxmox-clone.ubuntu-server-jammy"] + + # Provisioning the VM Template for Cloud-Init Integration in Proxmox #1 + 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" + ] + } + + # Provisioning the VM Template for Cloud-Init Integration in Proxmox #2 + provisioner "file" { + source = "ubuntu-noble/files/pve.cfg" + destination = "/tmp/pve.cfg" + } + + # Provisioning the VM Template for Cloud-Init Integration in Proxmox #3 + 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", + "sudo apt-get -y update" + ] + } +} \ No newline at end of file diff --git a/terraform/cloud-init.tf b/terraform/cloud-init.tf index ae35cdd..83c3f65 100644 --- a/terraform/cloud-init.tf +++ b/terraform/cloud-init.tf @@ -30,8 +30,6 @@ resource "proxmox_virtual_environment_file" "cloud_config" { - su - mafyuh -c 'git clone https://git.mafyuh.dev/mafyuh/iac.git /home/mafyuh/iac' - su - mafyuh -c 'git config --global user.name "Mafyuh"' - su - mafyuh -c 'git config --global user.email "matt@mafyuh.com"' - - su - mafyuh -c 'echo "alias dcu=\'docker compose up -d\'" >> /home/mafyuh/.bashrc - - su - mafyuh -c 'echo "alias dcd=\'docker compose down\'" >> /home/mafyuh/.bashrc - echo "done" > /tmp/cloud-config.done EOF @@ -67,8 +65,6 @@ resource "proxmox_virtual_environment_file" "cloud_config2" { - su - mafyuh -c 'git clone https://git.mafyuh.dev/mafyuh/iac.git /home/mafyuh/iac' - su - mafyuh -c 'git config --global user.name "Mafyuh"' - su - mafyuh -c 'git config --global user.email "matt@mafyuh.com"' - - su - mafyuh -c 'echo "alias dcu=\'docker compose up -d\'" >> /home/mafyuh/.bashrc - - su - mafyuh -c 'echo "alias dcd=\'docker compose down\'" >> /home/mafyuh/.bashrc - echo "done" > /tmp/cloud-config.done EOF diff --git a/terraform/kasm.tf b/terraform/kasm.tf index 8cd1f6f..82ba43b 100644 --- a/terraform/kasm.tf +++ b/terraform/kasm.tf @@ -5,7 +5,7 @@ resource "proxmox_virtual_environment_vm" "Kasm" { vm_id = 333 name = "Kasm" description = "kasm" - tags = ["tofu", "ubuntu-22", "auto-homelab-repo"] + tags = ["tofu", "ubuntu-22", "iac-repo"] started = true agent {