Compare commits
	
		
			1 Commits
		
	
	
		
			8d9eea6728
			...
			destroy
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|   | f90075f098 | 
| @@ -16,7 +16,6 @@ jobs: | |||||||
|       pull-requests: write |       pull-requests: write | ||||||
|  |  | ||||||
|     env: |     env: | ||||||
|       TF_VAR_SSH_KEY: ${{ secrets.SSH_KEY }} |  | ||||||
|       TF_VAR_TS_AUTHKEY: ${{ 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 }} | ||||||
|  |  | ||||||
|   | |||||||
| @@ -2,7 +2,9 @@ name: Gitea Destroy Terraform | |||||||
| run-name: ${{ gitea.actor }} triggered a Terraform Destroy 🧨 | run-name: ${{ gitea.actor }} triggered a Terraform Destroy 🧨 | ||||||
|  |  | ||||||
| on: | on: | ||||||
|   workflow_dispatch: # Manual trigger |   push: | ||||||
|  |     branches: | ||||||
|  |       - destroy | ||||||
|  |  | ||||||
| jobs: | jobs: | ||||||
|   destroy: |   destroy: | ||||||
| @@ -14,11 +16,9 @@ jobs: | |||||||
|       pull-requests: write |       pull-requests: write | ||||||
|  |  | ||||||
|     env: |     env: | ||||||
|         TF_VAR_SSH_KEY: ${{ secrets.SSH_KEY }} |  | ||||||
|       TF_VAR_TS_AUTHKEY: ${{ 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: |     steps: | ||||||
|       - name: Checkout repository |       - name: Checkout repository | ||||||
|         uses: actions/checkout@v4 |         uses: actions/checkout@v4 | ||||||
|   | |||||||
| @@ -17,9 +17,10 @@ jobs: | |||||||
|       pull-requests: write |       pull-requests: write | ||||||
|  |  | ||||||
|     env: |     env: | ||||||
|       TF_VAR_SSH_KEY: ${{ secrets.SSH_KEY }} |       TF_VAR_TAILSCALE_KEY: ${{ secrets.TAILSCALE_KEY }} | ||||||
|       TF_VAR_TS_AUTHKEY: ${{ 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: |     steps: | ||||||
|       - name: Checkout repository |       - name: Checkout repository | ||||||
|   | |||||||
| @@ -1,17 +1,70 @@ | |||||||
| ### Global cloud-init template (for all VMs) | ### Alpaca cloud-init template | ||||||
|  | data "template_file" "cloud_init_alpaca" { | ||||||
| data "template_file" "cloud_init_global" { |   count    = var.alpaca_vm_count | ||||||
|   template = file("${path.module}/files/cloud_init_global.yaml") |   template = file("${path.module}/files/cloud_init.yaml") | ||||||
|  |  | ||||||
|   vars = { |   vars = { | ||||||
|     hostname   = "generic" |     ssh_key    = var.ssh_key | ||||||
|  |     hostname   = "alpaca-${count.index + 1}" | ||||||
|     domain     = "home.arpa" |     domain     = "home.arpa" | ||||||
|     TS_AUTHKEY = var.TS_AUTHKEY |     TS_AUTHKEY = var.TS_AUTHKEY | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
| resource "local_file" "cloud_init_global" { |  | ||||||
|   content  = data.template_file.cloud_init_global.rendered | resource "local_file" "cloud_init_alpaca" { | ||||||
|   filename = "${path.module}/files/cloud_init_global.yaml" |   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" | ||||||
|  |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,9 +1,10 @@ | |||||||
| #cloud-config | #cloud-config | ||||||
| hostname: ${hostname} | hostname: ${hostname} | ||||||
| fqdn: ${hostname}.${domain} | fqdn: ${hostname}.${domain} | ||||||
|  | ssh_authorized_keys: | ||||||
|  |   - ${ssh_key} | ||||||
|  |  | ||||||
| runcmd: | runcmd: | ||||||
|   - curl -fsSL https://tailscale.com/install.sh | sh |   - curl -fsSL https://tailscale.com/install.sh | sh | ||||||
|   - tailscale up --auth-key=${TS_AUTHKEY} |   - tailscale up --auth-key=${TS_AUTHKEY} | ||||||
|   - tailscale set --ssh |  | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,6 +0,0 @@ | |||||||
| #cloud-config |  | ||||||
| runcmd: |  | ||||||
|   - curl -fsSL https://tailscale.com/install.sh | sh |  | ||||||
|   - tailscale up --auth-key=${TS_AUTHKEY} |  | ||||||
|   - tailscale set --ssh |  | ||||||
|  |  | ||||||
| @@ -1,18 +0,0 @@ | |||||||
| #cloud-config |  | ||||||
| hostname: ${hostname} |  | ||||||
| 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}'] |  | ||||||
|  |  | ||||||
| @@ -20,7 +20,7 @@ resource "proxmox_vm_qemu" "alpacas" { | |||||||
|   vmid        = 500 + count.index + 1 |   vmid        = 500 + count.index + 1 | ||||||
|   target_node = var.target_node |   target_node = var.target_node | ||||||
|   clone       = var.clone_template |   clone       = var.clone_template | ||||||
|   full_clone  = true |   full_clone  = false | ||||||
|   agent       = 1 |   agent       = 1 | ||||||
|  |  | ||||||
|   sockets    = var.sockets |   sockets    = var.sockets | ||||||
| @@ -29,23 +29,14 @@ resource "proxmox_vm_qemu" "alpacas" { | |||||||
|   scsihw     = "virtio-scsi-pci" |   scsihw     = "virtio-scsi-pci" | ||||||
|   boot       = "order=scsi0" |   boot       = "order=scsi0" | ||||||
|   ipconfig0  = "ip=dhcp" |   ipconfig0  = "ip=dhcp" | ||||||
|   cicustom  = "user=local:snippets/cloud_init_global.yaml" |   cicustom   = "user=local:snippets/cloud_init_alpaca_${count.index + 1}.yaml" | ||||||
|  |   depends_on = [null_resource.upload_cloud_init_alpaca] | ||||||
|  |  | ||||||
|  |  | ||||||
|   disks { |  | ||||||
|     scsi { |  | ||||||
|       scsi0 { |  | ||||||
|   disk { |   disk { | ||||||
|  |     slot    = "scsi0" | ||||||
|  |     type    = "disk" | ||||||
|  |     storage = var.storage | ||||||
|     size    = var.disk_size |     size    = var.disk_size | ||||||
|           storage = var.storage |  | ||||||
|         } |  | ||||||
|       } |  | ||||||
|       scsi1 { |  | ||||||
|         cloudinit { |  | ||||||
|           storage = var.storage |  | ||||||
|         } |  | ||||||
|       } |  | ||||||
|     } |  | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   network { |   network { | ||||||
| @@ -62,7 +53,7 @@ resource "proxmox_vm_qemu" "llamas" { | |||||||
|   vmid        = 600 + count.index + 1 |   vmid        = 600 + count.index + 1 | ||||||
|   target_node = var.target_node |   target_node = var.target_node | ||||||
|   clone       = var.clone_template |   clone       = var.clone_template | ||||||
|   full_clone  = true |   full_clone  = false | ||||||
|   agent       = 1 |   agent       = 1 | ||||||
|  |  | ||||||
|   sockets    = var.sockets |   sockets    = var.sockets | ||||||
| @@ -71,22 +62,14 @@ resource "proxmox_vm_qemu" "llamas" { | |||||||
|   scsihw     = "virtio-scsi-pci" |   scsihw     = "virtio-scsi-pci" | ||||||
|   boot       = "order=scsi0" |   boot       = "order=scsi0" | ||||||
|   ipconfig0  = "ip=dhcp" |   ipconfig0  = "ip=dhcp" | ||||||
|   cicustom  = "user=local:snippets/cloud_init_global.yaml" |   cicustom   = "user=local:snippets/cloud_init_llama_${count.index + 1}.yaml" | ||||||
|  |   depends_on = [null_resource.upload_cloud_init_llama] | ||||||
|  |  | ||||||
|   disks { |  | ||||||
|     scsi { |  | ||||||
|       scsi0 { |  | ||||||
|   disk { |   disk { | ||||||
|  |     slot    = "scsi0" | ||||||
|  |     type    = "disk" | ||||||
|  |     storage = var.storage | ||||||
|     size    = var.disk_size |     size    = var.disk_size | ||||||
|           storage = var.storage |  | ||||||
|         } |  | ||||||
|       } |  | ||||||
|       scsi1 { |  | ||||||
|         cloudinit { |  | ||||||
|           storage = var.storage |  | ||||||
|         } |  | ||||||
|       } |  | ||||||
|     } |  | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   network { |   network { | ||||||
|   | |||||||
| @@ -1,6 +1,6 @@ | |||||||
| { | { | ||||||
|   "version": 4, |   "version": 4, | ||||||
|   "terraform_version": "1.8.3", |   "terraform_version": "1.11.4", | ||||||
|   "serial": 31, |   "serial": 31, | ||||||
|   "lineage": "7a39dd41-1655-172c-950b-b8c5398caf69", |   "lineage": "7a39dd41-1655-172c-950b-b8c5398caf69", | ||||||
|   "outputs": {}, |   "outputs": {}, | ||||||
|   | |||||||
| @@ -79,3 +79,9 @@ variable "TS_AUTHKEY" { | |||||||
|   description = "Tailscale auth key used in cloud-init" |   description = "Tailscale auth key used in cloud-init" | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
|  | variable "ssh_key" { | ||||||
|  |   type        = string | ||||||
|  |   description = "Public SSH key used by cloud-init" | ||||||
|  | } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user