fix: align VM boot disk and add Terraform safety workflows #21

Merged
micqdf merged 4 commits from stage into master 2026-02-28 01:27:00 +00:00
4 changed files with 123 additions and 30 deletions

View File

@@ -5,6 +5,10 @@ on:
branches: branches:
- master - master
concurrency:
group: terraform-global
cancel-in-progress: false
jobs: jobs:
terraform: terraform:
name: "Terraform Apply" name: "Terraform Apply"
@@ -47,11 +51,24 @@ jobs:
- name: Terraform Plan - name: Terraform Plan
working-directory: terraform working-directory: terraform
run: terraform plan run: terraform plan -out=tfplan
- name: Block accidental destroy
env:
ALLOW_TF_DESTROY: ${{ secrets.ALLOW_TF_DESTROY }}
working-directory: terraform
run: |
terraform show -json -no-color tfplan > tfplan.json
DESTROY_COUNT=$(python3 -c 'import json; raw=open("tfplan.json","rb").read().decode("utf-8","ignore"); start=raw.find("{"); data=json.JSONDecoder().raw_decode(raw[start:])[0]; print(sum(1 for rc in data.get("resource_changes", []) if "delete" in rc.get("change", {}).get("actions", [])))')
echo "Planned deletes: $DESTROY_COUNT"
if [ "$DESTROY_COUNT" -gt 0 ] && [ "${ALLOW_TF_DESTROY}" != "true" ]; then
echo "Destroy actions detected. Set ALLOW_TF_DESTROY=true to allow."
exit 1
fi
- name: Terraform Apply - name: Terraform Apply
working-directory: terraform working-directory: terraform
run: terraform apply -auto-approve run: terraform apply -auto-approve tfplan
- name: Enroll VMs in Tailscale - name: Enroll VMs in Tailscale
env: env:

View File

@@ -1,28 +1,65 @@
name: Gitea Destroy Terraform name: Terraform Destroy
run-name: ${{ gitea.actor }} triggered a Terraform Destroy 🧨 run-name: ${{ gitea.actor }} requested Terraform destroy
on: on:
workflow_dispatch: # Manual trigger workflow_dispatch:
inputs:
confirm:
description: "Type NUKE to confirm destroy"
required: true
type: string
target:
description: "Destroy scope"
required: true
default: all
type: choice
options:
- all
- alpacas
- llamas
concurrency:
group: terraform-global
cancel-in-progress: false
jobs: jobs:
destroy: destroy:
name: "Terraform Destroy" name: "Terraform Destroy"
runs-on: ubuntu-latest runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
env:
TF_VAR_SSH_KEY: ${{ secrets.TF_VAR_SSH_KEY_PUBLIC }}
TF_VAR_TS_AUTHKEY: ${{ secrets.TF_VAR_TS_AUTHKEY }}
TF_VAR_PROXMOX_PASSWORD: ${{ secrets.TF_VAR_PROXMOX_PASSWORD }}
steps: steps:
- name: Validate confirmation phrase
run: |
if [ "${{ inputs.confirm }}" != "NUKE" ]; then
echo "Confirmation failed. You must type NUKE."
exit 1
fi
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Create Terraform secret files
working-directory: terraform
run: |
cat > secrets.auto.tfvars << EOF
pm_api_token_secret = "${{ secrets.PM_API_TOKEN_SECRET }}"
EOF
cat > backend.hcl << EOF
bucket = "${{ secrets.B2_TF_BUCKET }}"
key = "terraform.tfstate"
region = "us-east-005"
endpoints = {
s3 = "${{ secrets.B2_TF_ENDPOINT }}"
}
access_key = "$(printf '%s' "${{ secrets.B2_KEY_ID }}" | tr -d '\r\n')"
secret_key = "$(printf '%s' "${{ secrets.B2_APPLICATION_KEY }}" | tr -d '\r\n')"
skip_credentials_validation = true
skip_metadata_api_check = true
skip_region_validation = true
skip_requesting_account_id = true
use_path_style = true
EOF
- name: Set up Terraform - name: Set up Terraform
uses: hashicorp/setup-terraform@v2 uses: hashicorp/setup-terraform@v2
with: with:
@@ -30,9 +67,27 @@ jobs:
- name: Terraform Init - name: Terraform Init
working-directory: terraform working-directory: terraform
run: terraform init run: terraform init -reconfigure -backend-config=backend.hcl
- name: Terraform Destroy - name: Terraform Destroy Plan
working-directory: terraform working-directory: terraform
run: terraform destroy -auto-approve run: |
case "${{ inputs.target }}" in
all)
terraform plan -destroy -out=tfdestroy
;;
alpacas)
terraform plan -destroy -target=proxmox_vm_qemu.alpacas -out=tfdestroy
;;
llamas)
terraform plan -destroy -target=proxmox_vm_qemu.llamas -out=tfdestroy
;;
*)
echo "Invalid destroy target: ${{ inputs.target }}"
exit 1
;;
esac
- name: Terraform Destroy Apply
working-directory: terraform
run: terraform apply -auto-approve tfdestroy

View File

@@ -6,6 +6,10 @@ on:
- stage - stage
- test - test
concurrency:
group: terraform-global
cancel-in-progress: false
jobs: jobs:
terraform: terraform:
name: "Terraform Plan" name: "Terraform Plan"
@@ -63,6 +67,19 @@ jobs:
working-directory: terraform working-directory: terraform
run: terraform plan -out=tfplan run: terraform plan -out=tfplan
- name: Block accidental destroy
env:
ALLOW_TF_DESTROY: ${{ secrets.ALLOW_TF_DESTROY }}
working-directory: terraform
run: |
terraform show -json -no-color tfplan > tfplan.json
DESTROY_COUNT=$(python3 -c 'import json; raw=open("tfplan.json","rb").read().decode("utf-8","ignore"); start=raw.find("{"); data=json.JSONDecoder().raw_decode(raw[start:])[0]; print(sum(1 for rc in data.get("resource_changes", []) if "delete" in rc.get("change", {}).get("actions", [])))')
echo "Planned deletes: $DESTROY_COUNT"
if [ "$DESTROY_COUNT" -gt 0 ] && [ "${ALLOW_TF_DESTROY}" != "true" ]; then
echo "Destroy actions detected. Set ALLOW_TF_DESTROY=true to allow."
exit 1
fi
- name: Upload Terraform Plan - name: Upload Terraform Plan
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v3
with: with:

View File

@@ -26,19 +26,21 @@ resource "proxmox_vm_qemu" "alpacas" {
os_type = "cloud-init" os_type = "cloud-init"
agent = 1 agent = 1
sockets = var.sockets cpu {
cores = var.cores sockets = var.sockets
cores = var.cores
}
memory = var.memory memory = var.memory
scsihw = "virtio-scsi-pci" scsihw = "virtio-scsi-pci"
boot = "order=virtio0" boot = "order=scsi0"
bootdisk = "virtio0" bootdisk = "scsi0"
ipconfig0 = "ip=dhcp" ipconfig0 = "ip=dhcp"
cicustom = "user=local:snippets/cloud_init_global.yaml" cicustom = "user=local:snippets/cloud_init_global.yaml"
disks { disks {
virtio { scsi {
virtio0 { scsi0 {
disk { disk {
size = var.disk_size size = var.disk_size
storage = var.storage storage = var.storage
@@ -73,18 +75,20 @@ resource "proxmox_vm_qemu" "llamas" {
os_type = "cloud-init" os_type = "cloud-init"
agent = 1 agent = 1
sockets = var.sockets cpu {
cores = var.cores sockets = var.sockets
cores = var.cores
}
memory = var.memory memory = var.memory
scsihw = "virtio-scsi-pci" scsihw = "virtio-scsi-pci"
boot = "order=virtio0" boot = "order=scsi0"
bootdisk = "virtio0" bootdisk = "scsi0"
ipconfig0 = "ip=dhcp" ipconfig0 = "ip=dhcp"
cicustom = "user=local:snippets/cloud_init_global.yaml" cicustom = "user=local:snippets/cloud_init_global.yaml"
disks { disks {
virtio { scsi {
virtio0 { scsi0 {
disk { disk {
size = var.disk_size size = var.disk_size
storage = var.storage storage = var.storage