From a7ac8d678ca61581e767c8a5843ffc81076170db Mon Sep 17 00:00:00 2001 From: Matt Reeves Date: Thu, 1 Aug 2024 21:36:12 -0400 Subject: [PATCH] testing --- docker/scripts/kasm.sh | 7 ++ packer/ubuntu-jammy/ubuntu-jammy.pkr.hcl | 14 ++- terraform/cloud-init.tf | 1 - terraform/kasm.tf | 122 ++++++++++++----------- terraform/test.tf | 63 ------------ terraform/vars.tf | 4 + 6 files changed, 86 insertions(+), 125 deletions(-) create mode 100644 docker/scripts/kasm.sh delete mode 100644 terraform/test.tf diff --git a/docker/scripts/kasm.sh b/docker/scripts/kasm.sh new file mode 100644 index 0000000..ebd90e1 --- /dev/null +++ b/docker/scripts/kasm.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +# Navigate to the directory +cd /home/mafyuh/iac/docker/kasm + +# Run the command +dcu diff --git a/packer/ubuntu-jammy/ubuntu-jammy.pkr.hcl b/packer/ubuntu-jammy/ubuntu-jammy.pkr.hcl index dd9bf2f..ee624ed 100644 --- a/packer/ubuntu-jammy/ubuntu-jammy.pkr.hcl +++ b/packer/ubuntu-jammy/ubuntu-jammy.pkr.hcl @@ -31,10 +31,13 @@ source "proxmox-clone" "ubuntu-server-jammy" { # VM General Settings node = "pve2" + + ## See https://git.mafyuh.dev/mafyuh/iac/src/branch/main/terraform/ubuntu22-template2.tf clone_vm_id = "8101" - vm_id = "9636" + + vm_id = "9999" vm_name = "ubuntu-server-jammy" - template_description = "Ubuntu Server jammy Image" + template_description = "Custom Ubuntu Server see https://git.mafyuh.dev/mafyuh/iac/src/branch/main/packer/ubuntu-jammy/ubuntu-jammy.pkr.hcl" # VM System Settings qemu_agent = true @@ -43,7 +46,7 @@ source "proxmox-clone" "ubuntu-server-jammy" { scsi_controller = "virtio-scsi-pci" disks { - disk_size = "5G" + disk_size = "4G" format = "raw" storage_pool = "Fast500Gb" type = "virtio" @@ -65,6 +68,7 @@ source "proxmox-clone" "ubuntu-server-jammy" { ssh_username = "mafyuh" + # WSL Filesystem ssh_private_key_file = "~/.ssh/id_rsa" } @@ -74,7 +78,7 @@ build { name = "ubuntu-server-jammy" sources = ["source.proxmox-clone.ubuntu-server-jammy"] - + ## Cleanup for re-template provisioner "shell" { inline = [ "while [ ! -f /var/lib/cloud/instance/boot-finished ]; do echo 'Waiting for cloud-init...'; sleep 1; done", @@ -101,7 +105,7 @@ build { inline = [ "sudo cp /tmp/pve.cfg /etc/cloud/cloud.cfg.d/pve.cfg" ] } - # Provisioning the VM Template with Docker Installation #4 + # 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", diff --git a/terraform/cloud-init.tf b/terraform/cloud-init.tf index 46d742e..f322133 100644 --- a/terraform/cloud-init.tf +++ b/terraform/cloud-init.tf @@ -63,7 +63,6 @@ resource "proxmox_virtual_environment_file" "cloud_config2" { sudo: ALL=(ALL) NOPASSWD:ALL runcmd: - apt update - - apt install -y qemu-guest-agent - timedatectl set-timezone America/New_York - systemctl enable qemu-guest-agent - systemctl start qemu-guest-agent diff --git a/terraform/kasm.tf b/terraform/kasm.tf index 82ba43b..ad4c440 100644 --- a/terraform/kasm.tf +++ b/terraform/kasm.tf @@ -1,64 +1,74 @@ resource "proxmox_virtual_environment_vm" "Kasm" { + # VM General Settings + node_name = "pve2" + vm_id = 333 + name = "Kasm" + description = "kasm" + tags = ["tofu", "ubuntu-22", "iac-repo"] + started = true - # VM General Settings - node_name = "pve2" - vm_id = 333 - name = "Kasm" - description = "kasm" - tags = ["tofu", "ubuntu-22", "iac-repo"] - started = true + agent { + enabled = true + } - agent { - enabled = true + clone { + vm_id = 9999 + } + + # VM CPU Settings + cpu { + cores = 4 + type = "host" + architecture = "x86_64" + } + + # VM Memory Settings + memory { + dedicated = 4096 + } + + # VM Network Settings + network_device { + bridge = "vmbr0" + vlan_id = 1 + } + + # VM Disk Settings + disk { + datastore_id = "local-lvm" + size = 100 + interface = "scsi0" + } + + initialization { + ip_config { + ipv4 { + address = var.kasm_ip + gateway = var.vlan_gateway + } } - clone { - vm_id = 8101 - } - - # VM CPU Settings - cpu { - cores = 4 - type = "host" - architecture = "x86_64" - } - - # VM Memory Settings - memory { - dedicated = 4096 - } + user_data_file_id = proxmox_virtual_environment_file.cloud_config2.id + } - # VM Network Settings - network_device { - bridge = "vmbr0" - vlan_id = 1 - } - - # VM Disk Settings - disk { - datastore_id = "local-lvm" - size = 100 - interface = "scsi0" - } - - initialization { - ip_config { - ipv4 { - address = var.kasm_ip - gateway = var.vlan_gateway - } - } - - user_data_file_id = proxmox_virtual_environment_file.cloud_config2.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 - ] - } + 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 + ] + } +provisioner "remote-exec" { + inline = [ + "sudo bash /home/mafyuh/iac/docker/scripts/kasm.sh" + ] + connection { + type = "ssh" + user = "mafyuh" + private_key = file("/home/mafyuh/.ssh/id_rsa") + host = var.kasm_ssh_ip + } } +} \ No newline at end of file diff --git a/terraform/test.tf b/terraform/test.tf deleted file mode 100644 index 87c0ac6..0000000 --- a/terraform/test.tf +++ /dev/null @@ -1,63 +0,0 @@ -resource "proxmox_virtual_environment_vm" "test" { - - # VM General Settings - node_name = "pve2" - vm_id = 335 - name = "test" - description = "test" - tags = ["tofu", "ubuntu-22", "iac-repo"] - started = true - - agent { - enabled = true - } - - clone { - vm_id = 9636 - } - - # VM CPU Settings - cpu { - cores = 4 - type = "host" - architecture = "x86_64" - } - - # VM Memory Settings - memory { - dedicated = 4096 - } - - # VM Network Settings - network_device { - bridge = "vmbr0" - vlan_id = 1 - } - - # VM Disk Settings - disk { - datastore_id = "Fast500Gb" - size = 10 - interface = "scsi0" - } - - initialization { - ip_config { - ipv4 { - address = "dhcp" - } - } - - user_data_file_id = proxmox_virtual_environment_file.cloud_config2.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 - ] - } - -} diff --git a/terraform/vars.tf b/terraform/vars.tf index 47448eb..cb9fecd 100644 --- a/terraform/vars.tf +++ b/terraform/vars.tf @@ -48,4 +48,8 @@ variable "init_password" { variable "kasm_ip" { type = string +} + +variable "kasm_ssh_ip" { + type = string } \ No newline at end of file