add ubu and packer template for node 1

This commit is contained in:
Matt Reeves 2024-09-14 23:16:21 -04:00
parent bbb8d0a121
commit 6af7d30151
3 changed files with 194 additions and 0 deletions

View file

@ -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"
]
}
}

71
terraform/ubu.tf Normal file
View file

@ -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]
}

View file

@ -53,3 +53,7 @@ variable "kasm_ip" {
variable "kasm_ssh_ip" { variable "kasm_ssh_ip" {
type = string type = string
} }
variable "ubu_ip_address" {
type = string
}