Skip to content

Commit 6af7d30

Browse files
committedSep 15, 2024
add ubu and packer template for node 1
1 parent bbb8d0a commit 6af7d30

File tree

3 files changed

+194
-0
lines changed

3 files changed

+194
-0
lines changed
 
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
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-jammy2" {
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+
35+
clone_vm_id = "8100"
36+
37+
vm_id = "9998"
38+
vm_name = "ubuntu-server-jammy2"
39+
template_description = "Custom Ubuntu Server see https://git.mafyuh.dev/mafyuh/iac/src/branch/main/packer/ubuntu-jammy/ubuntu-jammy2.pkr.hcl"
40+
41+
# VM System Settings
42+
qemu_agent = true
43+
44+
# VM Hard Disk Settings
45+
scsi_controller = "virtio-scsi-pci"
46+
47+
disks {
48+
disk_size = "4G"
49+
format = "raw"
50+
storage_pool = "Fast2Tb"
51+
type = "virtio"
52+
}
53+
54+
# VM CPU Settings
55+
cores = "2"
56+
cpu_type = "x86-64-v2-AES"
57+
58+
# VM Memory Settings
59+
memory = "2048"
60+
61+
# VM Network Settings
62+
network_adapters {
63+
model = "virtio"
64+
bridge = "vmbr0"
65+
firewall = "false"
66+
}
67+
68+
69+
ssh_username = "mafyuh"
70+
# WSL Filesystem
71+
ssh_private_key_file = "~/.ssh/id_rsa"
72+
}
73+
74+
75+
build {
76+
77+
name = "ubuntu-server-jammy2"
78+
sources = ["source.proxmox-clone.ubuntu-server-jammy2"]
79+
80+
## Cleanup for re-template
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+
97+
provisioner "file" {
98+
source = "files/pve.cfg"
99+
destination = "/tmp/pve.cfg"
100+
}
101+
102+
103+
provisioner "shell" {
104+
inline = [ "sudo cp /tmp/pve.cfg /etc/cloud/cloud.cfg.d/pve.cfg" ]
105+
}
106+
107+
# Install Commonly Used Things - add alias's - set git config
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+
"echo \"alias dcd='docker compose down'\" >> ~/.bashrc",
114+
"git config --global user.name \"Mafyuh\"",
115+
"git config --global user.email \"matt@mafyuh.com\"",
116+
"sudo apt-get -y update"
117+
]
118+
}
119+
}

‎terraform/ubu.tf

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
resource "proxmox_virtual_environment_vm" "Ubu" {
2+
3+
# VM General Settings
4+
node_name = "prox"
5+
vm_id = 5000
6+
name = "Ubu"
7+
description = "My attempt to move things to 1 VM"
8+
tags = ["tofu", "ubuntu-22", "auto-homelab-repo", "infrastructure"]
9+
10+
agent {
11+
enabled = true # read 'Qemu guest agent' section, change to true only when ready
12+
}
13+
14+
clone {
15+
vm_id = 9998
16+
}
17+
18+
# VM CPU Settings
19+
cpu {
20+
cores = 2
21+
type = "host"
22+
architecture = "x86_64"
23+
}
24+
25+
# VM Memory Settings
26+
memory {
27+
dedicated = 6144
28+
}
29+
30+
# VM Network Settings
31+
network_device {
32+
bridge = "vmbr0"
33+
vlan_id = 1
34+
}
35+
36+
# VM Disk Settings
37+
disk {
38+
datastore_id = "Fast2Tb"
39+
size = 120
40+
interface = "scsi0"
41+
}
42+
43+
vga {
44+
type = "serial0"
45+
}
46+
47+
initialization {
48+
ip_config {
49+
ipv4 {
50+
address = var.ubu_ip_address
51+
gateway = var.vlan_gateway
52+
}
53+
}
54+
55+
user_data_file_id = proxmox_virtual_environment_file.cloud_config.id
56+
}
57+
58+
lifecycle {
59+
ignore_changes = [
60+
initialization[0].user_account[0].keys,
61+
initialization[0].user_account[0].password,
62+
initialization[0].user_account[0].username,
63+
initialization[0].user_data_file_id
64+
]
65+
}
66+
67+
}
68+
69+
output "vm_ipv4_address" {
70+
value = proxmox_virtual_environment_vm.Ubu.ipv4_addresses[1][0]
71+
}

‎terraform/vars.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,8 @@ variable "kasm_ip" {
5252

5353
variable "kasm_ssh_ip" {
5454
type = string
55+
}
56+
57+
variable "ubu_ip_address" {
58+
type = string
5559
}

0 commit comments

Comments
 (0)
Please sign in to comment.