Compare commits

1 Commits

Author SHA1 Message Date
MichaelFisher1997
f90075f098 terraform fmt
All checks were successful
Gitea Destroy Terraform / Terraform Destroy (push) Successful in 20s
2025-04-17 17:20:22 +01:00
11 changed files with 109 additions and 132 deletions

View File

@@ -16,7 +16,6 @@ jobs:
pull-requests: write
env:
TF_VAR_SSH_KEY: ${{ secrets.SSH_KEY }}
TF_VAR_TS_AUTHKEY: ${{ secrets.TAILSCALE_KEY }}
TF_VAR_ssh_key: ${{ secrets.SSH_PUBLIC_KEY }}

View File

@@ -2,7 +2,9 @@ name: Gitea Destroy Terraform
run-name: ${{ gitea.actor }} triggered a Terraform Destroy 🧨
on:
workflow_dispatch: # Manual trigger
push:
branches:
- destroy
jobs:
destroy:
@@ -14,10 +16,8 @@ jobs:
pull-requests: write
env:
TF_VAR_SSH_KEY: ${{ secrets.SSH_KEY }}
TF_VAR_TS_AUTHKEY: ${{ secrets.TAILSCALE_KEY }}
TF_VAR_ssh_key: ${{ secrets.SSH_PUBLIC_KEY }}
TF_VAR_TS_AUTHKEY: ${{ secrets.TAILSCALE_KEY }}
TF_VAR_ssh_key: ${{ secrets.SSH_PUBLIC_KEY }}
steps:
- name: Checkout repository

View File

@@ -17,9 +17,10 @@ jobs:
pull-requests: write
env:
TF_VAR_SSH_KEY: ${{ secrets.SSH_KEY }}
TF_VAR_TAILSCALE_KEY: ${{ secrets.TAILSCALE_KEY }}
TF_VAR_TS_AUTHKEY: ${{ secrets.TAILSCALE_KEY }}
# TF_VAR_ssh_key: ${{ secrets.SSH_PUBLIC_KEY }}
TF_VAR_ssh_key: ${{ secrets.SSH_PUBLIC_KEY }}
steps:
- name: Checkout repository

View File

@@ -1,32 +1,70 @@
### Global cloud-init template (for all VMs)
data "template_file" "cloud_init_global" {
template = file("${path.module}/files/cloud_init_global.yaml")
### Alpaca cloud-init template
data "template_file" "cloud_init_alpaca" {
count = var.alpaca_vm_count
template = file("${path.module}/files/cloud_init.yaml")
vars = {
hostname = "generic"
ssh_key = var.ssh_key
hostname = "alpaca-${count.index + 1}"
domain = "home.arpa"
TS_AUTHKEY = var.TS_AUTHKEY
}
}
resource "local_file" "cloud_init_global" {
content = data.template_file.cloud_init_global.rendered
filename = "${path.module}/files/cloud_init_global.yaml"
resource "local_file" "cloud_init_alpaca" {
count = var.alpaca_vm_count
content = data.template_file.cloud_init_alpaca[count.index].rendered
filename = "${path.module}/files/cloud_init_alpaca_${count.index + 1}.yaml"
}
resource "null_resource" "upload_cloud_init_alpaca" {
count = var.alpaca_vm_count
connection {
type = "ssh"
user = "root"
host = var.target_node
}
provisioner "file" {
source = local_file.cloud_init_alpaca[count.index].filename
destination = "/var/lib/vz/snippets/cloud_init_alpaca_${count.index + 1}.yaml"
}
}
### Llama cloud-init template
data "template_file" "cloud_init_llama" {
count = var.llama_vm_count
template = file("${path.module}/files/cloud_init.yaml")
vars = {
ssh_key = var.ssh_key
hostname = "llama-${count.index + 1}"
domain = "home.arpa"
TS_AUTHKEY = var.TS_AUTHKEY
}
}
resource "local_file" "cloud_init_llama" {
count = var.llama_vm_count
content = data.template_file.cloud_init_llama[count.index].rendered
filename = "${path.module}/files/cloud_init_llama_${count.index + 1}.yaml"
}
resource "null_resource" "upload_cloud_init_llama" {
count = var.llama_vm_count
connection {
type = "ssh"
user = "root"
host = var.target_node
}
provisioner "file" {
source = local_file.cloud_init_llama[count.index].filename
destination = "/var/lib/vz/snippets/cloud_init_llama_${count.index + 1}.yaml"
}
}
#resource "null_resource" "upload_cloud_init_alpaca" {
# count = var.alpaca_vm_count
#
# connection {
# type = "ssh"
# user = "root"
# private_key = var.ssh_key
# host = var.target_node
# }
#
# provisioner "file" {
# source = local_file.cloud_init_alpaca[count.index].filename
# destination = "/var/lib/vz/snippets/cloud_init_alpaca_${count.index + 1}.yaml"
# }
#}

View File

@@ -1,9 +1,10 @@
#cloud-config
hostname: ${hostname}
fqdn: ${hostname}.${domain}
ssh_authorized_keys:
- ${ssh_key}
runcmd:
- curl -fsSL https://tailscale.com/install.sh | sh
- tailscale up --auth-key=${TS_AUTHKEY}
- tailscale set --ssh

View File

@@ -1,6 +0,0 @@
#cloud-config
runcmd:
- curl -fsSL https://tailscale.com/install.sh | sh
- tailscale up --auth-key=${TS_AUTHKEY}
- tailscale set --ssh

View File

@@ -1,43 +0,0 @@
#cloud-config
package_update: true
package_upgrade: true
# APT fails to acquire GPG keys if package dirmngr is missing
bootcmd:
- [ cloud-init-per, once, dirmngr-aptupdate, apt-get, update ]
- [ cloud-init-per, once, dirmngr-aptinstall, apt-get, install, dirmngr, -y ]
- [ cloud-init-per, once, dirmngr-aptinstall, apt-get, install, gnupg2, -y ]
packages:
- jq
- curl
- qemu-guest-agent
- salt-minion
users:
- name: stuart
groups: sudo
shell: /bin/bash
sudo: ['ALL=(ALL) NOPASSWD:ALL']
ssh_authorized_keys:
- ${SSH_KEY_PUBLIC}
preserve_hostname: false
manage_etc_hosts: false
fqdn: ${hostname}.${domain}
#cloud-config
# The above header must generally appear on the first line of a cloud config
# file, but all other lines that begin with a # are optional comments.
runcmd:
# One-command install, from https://tailscale.com/download/
- ['sh', '-c', 'curl -fsSL https://tailscale.com/install.sh | sh']
# Set sysctl settings for IP forwarding (useful when configuring an exit node)
- ['sh', '-c', "echo 'net.ipv4.ip_forward = 1' | sudo tee -a /etc/sysctl.d/99-tailscale.conf && echo 'net.ipv6.conf.all.forwarding = 1' | sudo tee -a /etc/sysctl.d/99-tailscale.conf && sudo sysctl -p /etc/sysctl.d/99-tailscale.conf" ]
# Generate an auth key from your Admin console
# https://login.tailscale.com/admin/settings/keys
# and replace the placeholder below
- ['tailscale', 'up', '--auth-key=${TS_AUTHKEY}']

View File

@@ -20,33 +20,23 @@ resource "proxmox_vm_qemu" "alpacas" {
vmid = 500 + count.index + 1
target_node = var.target_node
clone = var.clone_template
full_clone = true
os_type = "cloud-init"
full_clone = false
agent = 1
sockets = var.sockets
cores = var.cores
memory = var.memory
scsihw = "virtio-scsi-pci"
boot = "order=scsi0"
ipconfig0 = "ip=dhcp"
cicustom = "user=local:snippets/cloud_init_global.yaml"
sockets = var.sockets
cores = var.cores
memory = var.memory
scsihw = "virtio-scsi-pci"
boot = "order=scsi0"
ipconfig0 = "ip=dhcp"
cicustom = "user=local:snippets/cloud_init_alpaca_${count.index + 1}.yaml"
depends_on = [null_resource.upload_cloud_init_alpaca]
disks {
scsi {
scsi0 {
disk {
size = var.disk_size
storage = var.storage
}
}
scsi1 {
cloudinit {
storage = var.storage
}
}
}
disk {
slot = "scsi0"
type = "disk"
storage = var.storage
size = var.disk_size
}
network {
@@ -63,32 +53,23 @@ resource "proxmox_vm_qemu" "llamas" {
vmid = 600 + count.index + 1
target_node = var.target_node
clone = var.clone_template
full_clone = true
os_type = "cloud-init"
full_clone = false
agent = 1
sockets = var.sockets
cores = var.cores
memory = var.memory
scsihw = "virtio-scsi-pci"
boot = "order=scsi0"
ipconfig0 = "ip=dhcp"
cicustom = "user=local:snippets/cloud_init_global.yaml"
sockets = var.sockets
cores = var.cores
memory = var.memory
scsihw = "virtio-scsi-pci"
boot = "order=scsi0"
ipconfig0 = "ip=dhcp"
cicustom = "user=local:snippets/cloud_init_llama_${count.index + 1}.yaml"
depends_on = [null_resource.upload_cloud_init_llama]
disks {
scsi {
scsi0 {
disk {
size = var.disk_size
storage = var.storage
}
}
scsi1 {
cloudinit {
storage = var.storage
}
}
}
disk {
slot = "scsi0"
type = "disk"
storage = var.storage
size = var.disk_size
}
network {

View File

@@ -1,6 +1,6 @@
{
"version": 4,
"terraform_version": "1.8.3",
"terraform_version": "1.11.4",
"serial": 31,
"lineage": "7a39dd41-1655-172c-950b-b8c5398caf69",
"outputs": {},

View File

@@ -1,8 +1,8 @@
target_node = "flex"
clone_template = "ubuntu-cloudinit"
clone_template = "Alpine-TemplateV2"
vm_name = "alpine-vm"
cores = 1
memory = 1024
cores = 2
memory = 2048
disk_size = "15G"
sockets = 1
bridge = "vmbr0"

View File

@@ -79,3 +79,9 @@ variable "TS_AUTHKEY" {
description = "Tailscale auth key used in cloud-init"
}
variable "ssh_key" {
type = string
description = "Public SSH key used by cloud-init"
}