working packer template with terraform clones
This commit is contained in:
parent
81c3941634
commit
ee6e38b07d
3 changed files with 83 additions and 16 deletions
|
@ -30,7 +30,7 @@ source "proxmox-clone" "ubuntu-server-jammy" {
|
||||||
insecure_skip_tls_verify = true
|
insecure_skip_tls_verify = true
|
||||||
|
|
||||||
# VM General Settings
|
# VM General Settings
|
||||||
node = "prox"
|
node = "pve2"
|
||||||
clone_vm_id = "8101"
|
clone_vm_id = "8101"
|
||||||
vm_id = "9636"
|
vm_id = "9636"
|
||||||
vm_name = "ubuntu-server-jammy"
|
vm_name = "ubuntu-server-jammy"
|
||||||
|
@ -45,7 +45,7 @@ source "proxmox-clone" "ubuntu-server-jammy" {
|
||||||
disks {
|
disks {
|
||||||
disk_size = "5G"
|
disk_size = "5G"
|
||||||
format = "raw"
|
format = "raw"
|
||||||
storage_pool = "Fast2Tb"
|
storage_pool = "Fast500Gb"
|
||||||
type = "virtio"
|
type = "virtio"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,23 +61,20 @@ source "proxmox-clone" "ubuntu-server-jammy" {
|
||||||
model = "virtio"
|
model = "virtio"
|
||||||
bridge = "vmbr0"
|
bridge = "vmbr0"
|
||||||
firewall = "false"
|
firewall = "false"
|
||||||
}
|
}
|
||||||
|
|
||||||
# VM Cloud-Init Settings
|
|
||||||
cloud_init = true
|
|
||||||
cloud_init_storage_pool = "local-lvm"
|
|
||||||
|
|
||||||
ssh_username = "mafyuh"
|
ssh_username = "mafyuh"
|
||||||
ssh_private_key_file = "~/.ssh/id_rsa"
|
ssh_private_key_file = "~/.ssh/id_rsa"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Build Definition to create the VM Template
|
|
||||||
build {
|
build {
|
||||||
|
|
||||||
name = "ubuntu-server-jammy"
|
name = "ubuntu-server-jammy"
|
||||||
sources = ["source.proxmox-clone.ubuntu-server-jammy"]
|
sources = ["source.proxmox-clone.ubuntu-server-jammy"]
|
||||||
|
|
||||||
# Provisioning the VM Template for Cloud-Init Integration in Proxmox #1
|
|
||||||
provisioner "shell" {
|
provisioner "shell" {
|
||||||
inline = [
|
inline = [
|
||||||
"while [ ! -f /var/lib/cloud/instance/boot-finished ]; do echo 'Waiting for cloud-init...'; sleep 1; done",
|
"while [ ! -f /var/lib/cloud/instance/boot-finished ]; do echo 'Waiting for cloud-init...'; sleep 1; done",
|
||||||
|
@ -93,13 +90,13 @@ build {
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
# Provisioning the VM Template for Cloud-Init Integration in Proxmox #2
|
|
||||||
provisioner "file" {
|
provisioner "file" {
|
||||||
source = "ubuntu-noble/files/pve.cfg"
|
source = "files/pve.cfg"
|
||||||
destination = "/tmp/pve.cfg"
|
destination = "/tmp/pve.cfg"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Provisioning the VM Template for Cloud-Init Integration in Proxmox #3
|
|
||||||
provisioner "shell" {
|
provisioner "shell" {
|
||||||
inline = [ "sudo cp /tmp/pve.cfg /etc/cloud/cloud.cfg.d/pve.cfg" ]
|
inline = [ "sudo cp /tmp/pve.cfg /etc/cloud/cloud.cfg.d/pve.cfg" ]
|
||||||
}
|
}
|
||||||
|
@ -110,6 +107,9 @@ build {
|
||||||
"sudo apt-get install -y ca-certificates curl gnupg lsb-release nfs-common qemu-guest-agent net-tools",
|
"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",
|
"curl -fsSL https://get.docker.com | sudo sh",
|
||||||
"echo \"alias dcu='docker compose up -d'\" >> ~/.bashrc",
|
"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"
|
"sudo apt-get -y update"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,10 @@ data "local_file" "ssh_public_key" {
|
||||||
filename = "/home/mafyuh/.ssh/main_key.pub"
|
filename = "/home/mafyuh/.ssh/main_key.pub"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data "local_file" "ssh_public_key_2" {
|
||||||
|
filename = "/home/mafyuh/.ssh/id_rsa.pub"
|
||||||
|
}
|
||||||
|
|
||||||
resource "proxmox_virtual_environment_file" "cloud_config" {
|
resource "proxmox_virtual_environment_file" "cloud_config" {
|
||||||
content_type = "snippets"
|
content_type = "snippets"
|
||||||
datastore_id = "Slow4tb"
|
datastore_id = "Slow4tb"
|
||||||
|
@ -19,6 +23,7 @@ resource "proxmox_virtual_environment_file" "cloud_config" {
|
||||||
shell: /bin/bash
|
shell: /bin/bash
|
||||||
ssh_authorized_keys:
|
ssh_authorized_keys:
|
||||||
- ${trimspace(data.local_file.ssh_public_key.content)}
|
- ${trimspace(data.local_file.ssh_public_key.content)}
|
||||||
|
- ${trimspace(data.local_file.ssh_public_key_2.content)}
|
||||||
sudo: ALL=(ALL) NOPASSWD:ALL
|
sudo: ALL=(ALL) NOPASSWD:ALL
|
||||||
runcmd:
|
runcmd:
|
||||||
- apt update
|
- apt update
|
||||||
|
@ -54,17 +59,16 @@ resource "proxmox_virtual_environment_file" "cloud_config2" {
|
||||||
shell: /bin/bash
|
shell: /bin/bash
|
||||||
ssh_authorized_keys:
|
ssh_authorized_keys:
|
||||||
- ${trimspace(data.local_file.ssh_public_key.content)}
|
- ${trimspace(data.local_file.ssh_public_key.content)}
|
||||||
|
- ${trimspace(data.local_file.ssh_public_key_2.content)}
|
||||||
sudo: ALL=(ALL) NOPASSWD:ALL
|
sudo: ALL=(ALL) NOPASSWD:ALL
|
||||||
runcmd:
|
runcmd:
|
||||||
- apt update
|
- apt update
|
||||||
- apt install -y qemu-guest-agent net-tools nfs-common
|
- apt install -y qemu-guest-agent
|
||||||
- timedatectl set-timezone America/New_York
|
- timedatectl set-timezone America/New_York
|
||||||
- systemctl enable qemu-guest-agent
|
- systemctl enable qemu-guest-agent
|
||||||
- systemctl start qemu-guest-agent
|
- systemctl start qemu-guest-agent
|
||||||
- curl -fsSL https://get.docker.com | sudo sh
|
- apt upgrade -y
|
||||||
- su - mafyuh -c 'git clone https://git.mafyuh.dev/mafyuh/iac.git /home/mafyuh/iac'
|
- 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"'
|
|
||||||
- echo "done" > /tmp/cloud-config.done
|
- echo "done" > /tmp/cloud-config.done
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
|
63
terraform/test.tf
Normal file
63
terraform/test.tf
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
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
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue