From 7a1ad932bfc01c72aacc73fb5c919bbe6313d495 Mon Sep 17 00:00:00 2001 From: Matt Reeves Date: Mon, 24 Jun 2024 17:36:44 -0400 Subject: [PATCH] fixing --- arm.tf | 68 ------------------------------------------- cloud-init.tf | 35 ++++++++++++++++++++++ ubuntu22-template.tf | 48 ++++++++++++++++++++++++++++++ ubuntu22-template2.tf | 48 ++++++++++++++++++++++++++++++ vars.tf | 8 +++++ 5 files changed, 139 insertions(+), 68 deletions(-) delete mode 100644 arm.tf create mode 100644 cloud-init.tf create mode 100644 ubuntu22-template.tf create mode 100644 ubuntu22-template2.tf diff --git a/arm.tf b/arm.tf deleted file mode 100644 index 15f1a18..0000000 --- a/arm.tf +++ /dev/null @@ -1,68 +0,0 @@ -resource "proxmox_virtual_environment_vm" "ARM" { - - # VM General Settings - node_name = "prox" - vm_id = 8100 - name = "ARM" - description = "Ubuntu 24 ARM" - tags = ["tofu", "ubuntu-22", "auto-homelab-repo", "infrastructure"] - bios = "ovmf" - started = false - - agent { - enabled = false # read 'Qemu guest agent' section, change to true only when ready - } - - # VM Memory Settings - memory { - dedicated = 2048 - } - - # VM Network Settings - network_device { - bridge = "vmbr0" - vlan_id = 1 - } - - # VM Disk Settings - disk { - datastore_id = "Fast2Tb" - file_id = proxmox_virtual_environment_download_file.latest_ubuntu_22_arm_jammy_qcow2_img.id - size = 100 - interface = "scsi0" - } - - efi_disk { - type = "4m" - } - - vga { - type = "serial0" - } - - initialization { - ip_config { - ipv4 { - address = "dhcp" - } - } - - user_account {} - } - - lifecycle { - ignore_changes = [ - initialization[0].user_account[0].keys, - initialization[0].user_account[0].password, - initialization[0].user_account[0].username, - ] - } - -} - -resource "proxmox_virtual_environment_download_file" "latest_ubuntu_22_arm_jammy_qcow2_img" { - content_type = "iso" - datastore_id = "local" - node_name = "prox" - url = "https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-arm64.img" - } \ No newline at end of file diff --git a/cloud-init.tf b/cloud-init.tf new file mode 100644 index 0000000..948f676 --- /dev/null +++ b/cloud-init.tf @@ -0,0 +1,35 @@ +data "local_file" "ssh_public_key" { + filename = "/home/mafyuh/.ssh/main_key.pub" +} + +resource "proxmox_virtual_environment_file" "cloud_config" { + content_type = "snippets" + datastore_id = "Slow4tb" + node_name = "prox" + + source_raw { + data = <<-EOF + #cloud-config + users: + - default + - name: mafyuh + groups: + - sudo + - docker + shell: /bin/bash + ssh_authorized_keys: + - ${trimspace(data.local_file.ssh_public_key.content)} + sudo: ALL=(ALL) NOPASSWD:ALL + runcmd: + - apt update + - apt install -y qemu-guest-agent net-tools nfs-common + - timedatectl set-timezone America/New_York + - systemctl enable qemu-guest-agent + - systemctl start qemu-guest-agent + - curl -fsSL https://get.docker.com | sudo sh + - echo "done" > /tmp/cloud-config.done + EOF + + file_name = "cloud-config.yaml" + } +} \ No newline at end of file diff --git a/ubuntu22-template.tf b/ubuntu22-template.tf new file mode 100644 index 0000000..a8b7203 --- /dev/null +++ b/ubuntu22-template.tf @@ -0,0 +1,48 @@ +resource "proxmox_virtual_environment_vm" "Ubuntu-22-Template" { + name = "ubuntu-22" + node_name = "prox" + vm_id = 8100 + tags = ["tofu", "ubuntu-22"] + template = true + started = false + + disk { + datastore_id = "Fast2Tb" + file_id = proxmox_virtual_environment_download_file.ubuntu_cloud_image_22.id + interface = "scsi0" + size = 4 + } + + agent { + enabled = true + } + + initialization { + ip_config { + ipv4 { + address = "dhcp" + } + } + + user_data_file_id = proxmox_virtual_environment_file.cloud_config.id +} + +serial_device {} + +network_device { + bridge = "vmbr0" +} + +vga { + type = "serial0" + } + +} + + +resource "proxmox_virtual_environment_download_file" "ubuntu_cloud_image_22" { + content_type = "iso" + datastore_id = "local" + node_name = "prox" + url = "https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img" +} diff --git a/ubuntu22-template2.tf b/ubuntu22-template2.tf new file mode 100644 index 0000000..4164b70 --- /dev/null +++ b/ubuntu22-template2.tf @@ -0,0 +1,48 @@ +resource "proxmox_virtual_environment_vm" "Ubuntu-22-Template2" { + name = "ubuntu-22" + node_name = "pve2" + vm_id = 8101 + tags = ["tofu", "ubuntu-22"] + template = true + started = false + + disk { + datastore_id = "local-lvm" + file_id = proxmox_virtual_environment_download_file.ubuntu_cloud_image_22_2.id + interface = "scsi0" + size = 4 + } + + agent { + enabled = true + } + + initialization { + ip_config { + ipv4 { + address = "dhcp" + } + } + + user_data_file_id = proxmox_virtual_environment_file.cloud_config.id +} + +serial_device {} + +network_device { + bridge = "vmbr0" +} + +vga { + type = "serial0" + } + +} + + +resource "proxmox_virtual_environment_download_file" "ubuntu_cloud_image_22_2" { + content_type = "iso" + datastore_id = "local" + node_name = "pve2" + url = "https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img" +} diff --git a/vars.tf b/vars.tf index f81f305..3462ab1 100644 --- a/vars.tf +++ b/vars.tf @@ -36,4 +36,12 @@ variable "prox_ip_address" { variable "npm_ip_address" { type = string +} + +variable "init_username" { + type = string +} + +variable "init_password" { + type = string } \ No newline at end of file