From 30c250c66a35718f232e1f07d428e3a2713ad67b Mon Sep 17 00:00:00 2001 From: MichaelFisher1997 Date: Thu, 17 Apr 2025 02:31:15 +0100 Subject: [PATCH] terraform plan --- .gitea/workflows/terraform-plan.yml | 4 ++++ .gitignore | 3 --- terraform/main.tf | 34 ++++++++++++++++++++++++----- terraform/outputs.tf | 28 ++++++++++++------------ terraform/terraform.tfvars | 13 +++++++++++ terraform/variables.tf | 12 +++++++--- 6 files changed, 69 insertions(+), 25 deletions(-) create mode 100644 terraform/terraform.tfvars diff --git a/.gitea/workflows/terraform-plan.yml b/.gitea/workflows/terraform-plan.yml index dfac06c..7bb7cba 100644 --- a/.gitea/workflows/terraform-plan.yml +++ b/.gitea/workflows/terraform-plan.yml @@ -21,6 +21,10 @@ jobs: with: terraform_version: 1.6.6 + - name: Inject sensitive secrets + run: | + echo 'proxmox_password = "${{ secrets.PROXMOX_PASSWORD }}"' >> terraform.tfvars + - name: Terraform Init run: terraform init diff --git a/.gitignore b/.gitignore index 3248866..e93f800 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,2 @@ ./terraform/.terraform -./terraform/terraform.tfvars -terraform.tfvars -*.tfvars terraform/.terraform/ diff --git a/terraform/main.tf b/terraform/main.tf index f03e2be..5b21c4a 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -14,10 +14,10 @@ provider "proxmox" { pm_tls_insecure = true } -resource "proxmox_vm_qemu" "alpine" { - count = var.vm_count - vmid = 400 + count.index + 1 - name = "Alpine-${count.index + 1}" +resource "proxmox_vm_qemu" "alpacas" { + count = var.alpaca_count + vmid = 500 + count.index + name = "alpaca-${count.index + 1}" target_node = var.target_node clone = var.clone_template sockets = var.sockets @@ -25,7 +25,6 @@ resource "proxmox_vm_qemu" "alpine" { memory = var.memory agent = 1 boot = "order=scsi0" - os_type = "cloud-init" disk { slot = "scsi0" @@ -39,7 +38,32 @@ resource "proxmox_vm_qemu" "alpine" { model = "virtio" bridge = var.bridge } +} +resource "proxmox_vm_qemu" "llamas" { + count = var.llama_count + vmid = 600 + count.index + name = "llama-${count.index + 1}" + target_node = var.target_node + clone = var.clone_template + sockets = var.sockets + cores = var.cores + memory = var.memory + agent = 1 + boot = "order=scsi0" + + disk { + slot = "scsi0" + type = "disk" + size = var.disk_size + storage = var.storage + } + + network { + id = 0 + model = "virtio" + bridge = var.bridge + } } diff --git a/terraform/outputs.tf b/terraform/outputs.tf index ffe9687..6c767ec 100644 --- a/terraform/outputs.tf +++ b/terraform/outputs.tf @@ -1,22 +1,22 @@ -output "vm_ids" { - description = "VM IDs by name" +output "alpaca_vm_ids" { value = { - for i in range(var.vm_count) : - "Alpine-${i + 1}" => proxmox_vm_qemu.alpine[i].vmid + for i in range(var.alpaca_count) : + "alpaca-${i + 1}" => proxmox_vm_qemu.alpacas[i].vmid } } -output "vm_names" { - description = "VM names" - value = [ - for vm in proxmox_vm_qemu.alpine : vm.name - ] +output "alpaca_vm_names" { + value = [for vm in proxmox_vm_qemu.alpacas : vm.name] } -output "vm_clones" { - description = "Template names each VM was cloned from" - value = [ - for vm in proxmox_vm_qemu.alpine : vm.clone - ] +output "llama_vm_ids" { + value = { + for i in range(var.llama_count) : + "llama-${i + 1}" => proxmox_vm_qemu.llamas[i].vmid + } +} + +output "llama_vm_names" { + value = [for vm in proxmox_vm_qemu.llamas : vm.name] } diff --git a/terraform/terraform.tfvars b/terraform/terraform.tfvars new file mode 100644 index 0000000..851acbb --- /dev/null +++ b/terraform/terraform.tfvars @@ -0,0 +1,13 @@ +target_node = "flex" +clone_template = "Alpine-Template" +vm_name = "alpine-vm" +cores = 2 +memory = 2048 +disk_size = "15G" +sockets = 1 +bridge = "vmbr0" +disk_type = "scsi" +storage = "Flash" +pm_api_url = "https://100.105.0.115:8006/api2/json" +pm_user = "terraform-prov@pve" + diff --git a/terraform/variables.tf b/terraform/variables.tf index 3c6ac6b..e412127 100644 --- a/terraform/variables.tf +++ b/terraform/variables.tf @@ -50,9 +50,15 @@ variable "pm_user" { type = string } -variable "vm_count" { +variable "alpaca_count" { type = number - description = "How many Alpine VMs to create" - default = 3 + default = 1 + description = "How many Alpaca VMs to create" +} + +variable "llama_count" { + type = number + default = 1 + description = "How many Llama VMs to create" }