From a349ce13f8561ad7a258997b93b77528e40ef350 Mon Sep 17 00:00:00 2001 From: Ryan Blundon Date: Sat, 7 Mar 2026 21:18:36 -0600 Subject: [PATCH] Added terraform for lightning-lane --- terraform/proxmox/hosts/.gitignore | 10 +++ terraform/proxmox/hosts/main.tf | 29 +++++++++ terraform/proxmox/hosts/outputs.tf | 21 +++++++ terraform/proxmox/hosts/providers.tf | 24 +++++++ terraform/proxmox/hosts/variables.tf | 94 ++++++++++++++++++++++++++++ 5 files changed, 178 insertions(+) create mode 100644 terraform/proxmox/hosts/.gitignore create mode 100644 terraform/proxmox/hosts/main.tf create mode 100644 terraform/proxmox/hosts/outputs.tf create mode 100644 terraform/proxmox/hosts/providers.tf create mode 100644 terraform/proxmox/hosts/variables.tf diff --git a/terraform/proxmox/hosts/.gitignore b/terraform/proxmox/hosts/.gitignore new file mode 100644 index 0000000..b93159b --- /dev/null +++ b/terraform/proxmox/hosts/.gitignore @@ -0,0 +1,10 @@ +# Terraform state files contain sensitive data — never commit +states/ + +# Terraform working directories +.terraform/ +.terraform.lock.hcl + +# Crash logs +crash.log +crash.*.log diff --git a/terraform/proxmox/hosts/main.tf b/terraform/proxmox/hosts/main.tf new file mode 100644 index 0000000..6c6aade --- /dev/null +++ b/terraform/proxmox/hosts/main.tf @@ -0,0 +1,29 @@ +# ─── Host Provisioning ─────────────────────────────────────────────────────── +# Root module that calls the shared VM module. +# Per-host values come from tfvars files. +# Sensitive values come from CLI arguments. +# +# Usage: +# terraform apply \ +# -var-file="tfvars/lightning-lane.tfvars" \ +# -state="states/lightning-lane.tfstate" \ +# -var="proxmox_api_url=https://main-street-usa.local.mk-labs.cloud:8006" \ +# -var="proxmox_api_token=terraform@pve!automation=" + +module "vm" { + source = "../vm" + + proxmox_api_url = var.proxmox_api_url + proxmox_api_token = var.proxmox_api_token + + hostname = var.hostname + vm_id = var.vm_id + ip_address = var.ip_address + target_node = var.target_node + clone_node = var.clone_node + template_name = var.template_name + datastore = var.datastore + bridge = var.bridge + dns_servers = var.dns_servers + search_domain = var.search_domain +} diff --git a/terraform/proxmox/hosts/outputs.tf b/terraform/proxmox/hosts/outputs.tf new file mode 100644 index 0000000..6e142c8 --- /dev/null +++ b/terraform/proxmox/hosts/outputs.tf @@ -0,0 +1,21 @@ +# ─── Outputs ───────────────────────────────────────────────────────────────── + +output "vm_id" { + description = "Proxmox VM ID" + value = module.vm.vm_id +} + +output "hostname" { + description = "VM hostname" + value = var.hostname +} + +output "ip_address" { + description = "VM IP address" + value = var.ip_address +} + +output "target_node" { + description = "Proxmox node the VM is placed on" + value = var.target_node +} diff --git a/terraform/proxmox/hosts/providers.tf b/terraform/proxmox/hosts/providers.tf new file mode 100644 index 0000000..062a66d --- /dev/null +++ b/terraform/proxmox/hosts/providers.tf @@ -0,0 +1,24 @@ +# ─── Provider Configuration ────────────────────────────────────────────────── +# Shared provider for all host deployments. +# Sensitive values are passed via CLI at apply time. + +terraform { + required_version = ">= 1.5" + + required_providers { + proxmox = { + source = "bpg/proxmox" + version = ">= 0.78.0" + } + } +} + +provider "proxmox" { + endpoint = var.proxmox_api_url + api_token = var.proxmox_api_token + insecure = true + + ssh { + agent = false + } +} diff --git a/terraform/proxmox/hosts/variables.tf b/terraform/proxmox/hosts/variables.tf new file mode 100644 index 0000000..b27dbfb --- /dev/null +++ b/terraform/proxmox/hosts/variables.tf @@ -0,0 +1,94 @@ +# ─── Provider Authentication ───────────────────────────────────────────────── +# Passed via CLI — never stored in tfvars. + +variable "proxmox_api_url" { + type = string + description = "Proxmox API endpoint URL (e.g., https://main-street-usa.local.mk-labs.cloud:8006)" +} + +variable "proxmox_api_token" { + type = string + description = "Proxmox API token in format: user@realm!token-name=token-secret" + sensitive = true +} + +# ─── VM Identity ───────────────────────────────────────────────────────────── + +variable "vm_id" { + type = number + description = "Proxmox VM ID. Convention: {third_octet}{fourth_octet:03d} (e.g., 10.1.71.35 → 71035)." +} + +variable "hostname" { + type = string + description = "VM hostname. Used as the Proxmox VM name and cloud-init hostname." +} + +variable "ip_address" { + type = string + description = "Primary IP address for the VM (without CIDR, e.g., 10.1.71.35)." +} + +variable "dns_servers" { + type = list(string) + description = "DNS servers for the VM." + default = ["10.1.71.1"] +} + +variable "search_domain" { + type = string + description = "DNS search domain for the VM." + default = "local.mk-labs.cloud" +} + +# ─── Proxmox Placement ────────────────────────────────────────────────────── + +variable "clone_node" { + type = string + description = "Proxmox node where templates live." + default = "fantasyland" +} + +variable "target_node" { + type = string + description = "Proxmox node for final VM placement." +} + +variable "datastore" { + type = string + description = "Proxmox storage pool for VM disks." + default = "liberty-tree" +} + +# ─── Template Selection ───────────────────────────────────────────────────── + +variable "template_name" { + type = string + description = "Name of the Proxmox VM template to clone." + + validation { + condition = contains([ + "ubuntu-24.04-small", + "ubuntu-24.04-medium", + "ubuntu-24.04-large", + "ubuntu-24.04-large-plus", + "ubuntu-24.04-xlarge", + "ubuntu-24.04-xlarge-plus", + ], var.template_name) + error_message = "template_name must be a valid Ubuntu 24.04 template." + } +} + +# ─── Network ───────────────────────────────────────────────────────────────── + +variable "vlan_id" { + type = number + description = "VLAN tag for the VM network interface." + default = 71 +} + +variable "bridge" { + type = string + description = "Proxmox network bridge for the VM." + default = "vmbr0" +}