Skip to content

Commit 81c3941

Browse files
committedAug 1, 2024
test packer
1 parent fa834a3 commit 81c3941

File tree

5 files changed

+120
-5
lines changed

5 files changed

+120
-5
lines changed
 

‎.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,5 @@ terraform.rc
4242
## Kubernetes
4343
/kubernetes/cluster/apps/staging
4444

45+
## Packer
46+
credentials.pkr.hcl

‎packer/ubuntu-noble/files/pve.cfg

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
datasource_list: [ConfigDrive, NoCloud]
+116
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
packer {
2+
required_plugins {
3+
name = {
4+
version = "~> 1"
5+
source = "github.com/hashicorp/proxmox"
6+
}
7+
}
8+
}
9+
10+
variable "proxmox_api_url" {
11+
type = string
12+
}
13+
14+
variable "proxmox_api_token_id" {
15+
type = string
16+
}
17+
18+
variable "proxmox_api_token_secret" {
19+
type = string
20+
sensitive = true
21+
}
22+
23+
# Resource Definiation for the VM Template
24+
source "proxmox-clone" "ubuntu-server-jammy" {
25+
26+
# Proxmox Connection Settings
27+
proxmox_url = "${var.proxmox_api_url}"
28+
username = "${var.proxmox_api_token_id}"
29+
token = "${var.proxmox_api_token_secret}"
30+
insecure_skip_tls_verify = true
31+
32+
# VM General Settings
33+
node = "prox"
34+
clone_vm_id = "8101"
35+
vm_id = "9636"
36+
vm_name = "ubuntu-server-jammy"
37+
template_description = "Ubuntu Server jammy Image"
38+
39+
# VM System Settings
40+
qemu_agent = true
41+
42+
# VM Hard Disk Settings
43+
scsi_controller = "virtio-scsi-pci"
44+
45+
disks {
46+
disk_size = "5G"
47+
format = "raw"
48+
storage_pool = "Fast2Tb"
49+
type = "virtio"
50+
}
51+
52+
# VM CPU Settings
53+
cores = "2"
54+
cpu_type = "x86-64-v2-AES"
55+
56+
# VM Memory Settings
57+
memory = "2048"
58+
59+
# VM Network Settings
60+
network_adapters {
61+
model = "virtio"
62+
bridge = "vmbr0"
63+
firewall = "false"
64+
}
65+
66+
# VM Cloud-Init Settings
67+
cloud_init = true
68+
cloud_init_storage_pool = "local-lvm"
69+
70+
ssh_username = "mafyuh"
71+
ssh_private_key_file = "~/.ssh/id_rsa"
72+
}
73+
74+
# Build Definition to create the VM Template
75+
build {
76+
77+
name = "ubuntu-server-jammy"
78+
sources = ["source.proxmox-clone.ubuntu-server-jammy"]
79+
80+
# Provisioning the VM Template for Cloud-Init Integration in Proxmox #1
81+
provisioner "shell" {
82+
inline = [
83+
"while [ ! -f /var/lib/cloud/instance/boot-finished ]; do echo 'Waiting for cloud-init...'; sleep 1; done",
84+
"sudo rm /etc/ssh/ssh_host_*",
85+
"sudo truncate -s 0 /etc/machine-id",
86+
"sudo apt -y autoremove --purge",
87+
"sudo apt -y clean",
88+
"sudo apt -y autoclean",
89+
"sudo cloud-init clean",
90+
"sudo rm -f /etc/cloud/cloud.cfg.d/subiquity-disable-cloudinit-networking.cfg",
91+
"sudo rm -f /etc/netplan/00-installer-config.yaml",
92+
"sudo sync"
93+
]
94+
}
95+
96+
# Provisioning the VM Template for Cloud-Init Integration in Proxmox #2
97+
provisioner "file" {
98+
source = "ubuntu-noble/files/pve.cfg"
99+
destination = "/tmp/pve.cfg"
100+
}
101+
102+
# Provisioning the VM Template for Cloud-Init Integration in Proxmox #3
103+
provisioner "shell" {
104+
inline = [ "sudo cp /tmp/pve.cfg /etc/cloud/cloud.cfg.d/pve.cfg" ]
105+
}
106+
107+
# Provisioning the VM Template with Docker Installation #4
108+
provisioner "shell" {
109+
inline = [
110+
"sudo apt-get install -y ca-certificates curl gnupg lsb-release nfs-common qemu-guest-agent net-tools",
111+
"curl -fsSL https://get.docker.com | sudo sh",
112+
"echo \"alias dcu='docker compose up -d'\" >> ~/.bashrc",
113+
"sudo apt-get -y update"
114+
]
115+
}
116+
}

‎terraform/cloud-init.tf

-4
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ resource "proxmox_virtual_environment_file" "cloud_config" {
3030
- su - mafyuh -c 'git clone https://git.mafyuh.dev/mafyuh/iac.git /home/mafyuh/iac'
3131
- su - mafyuh -c 'git config --global user.name "Mafyuh"'
3232
- su - mafyuh -c 'git config --global user.email "matt@mafyuh.com"'
33-
- su - mafyuh -c 'echo "alias dcu=\'docker compose up -d\'" >> /home/mafyuh/.bashrc
34-
- su - mafyuh -c 'echo "alias dcd=\'docker compose down\'" >> /home/mafyuh/.bashrc
3533
- echo "done" > /tmp/cloud-config.done
3634
EOF
3735

@@ -67,8 +65,6 @@ resource "proxmox_virtual_environment_file" "cloud_config2" {
6765
- su - mafyuh -c 'git clone https://git.mafyuh.dev/mafyuh/iac.git /home/mafyuh/iac'
6866
- su - mafyuh -c 'git config --global user.name "Mafyuh"'
6967
- su - mafyuh -c 'git config --global user.email "matt@mafyuh.com"'
70-
- su - mafyuh -c 'echo "alias dcu=\'docker compose up -d\'" >> /home/mafyuh/.bashrc
71-
- su - mafyuh -c 'echo "alias dcd=\'docker compose down\'" >> /home/mafyuh/.bashrc
7268
- echo "done" > /tmp/cloud-config.done
7369
EOF
7470

‎terraform/kasm.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ resource "proxmox_virtual_environment_vm" "Kasm" {
55
vm_id = 333
66
name = "Kasm"
77
description = "kasm"
8-
tags = ["tofu", "ubuntu-22", "auto-homelab-repo"]
8+
tags = ["tofu", "ubuntu-22", "iac-repo"]
99
started = true
1010

1111
agent {

0 commit comments

Comments
 (0)
Please sign in to comment.