Update terraform to use vm_id from n8n.

This commit is contained in:
2026-02-28 00:00:56 -06:00
parent 4964552483
commit d941557e88
8 changed files with 267 additions and 22 deletions

View File

@@ -1,12 +1,7 @@
# ─── VM ID Derivation ────────────────────────────────────────────────────────
# Convention carried from existing Ansible playbooks:
# ─── VM ID Convention ────────────────────────────────────────────────────────
# VM ID = {third_octet}{fourth_octet:03d}
# Example: 10.1.71.35 → 71035
locals {
ip_octets = split(".", var.ip_address)
vm_id = tonumber("${local.ip_octets[2]}${format("%03d", tonumber(local.ip_octets[3]))}")
}
# Computed by n8n and passed as a variable to keep the logic in one place.
# ─── Template Lookup ─────────────────────────────────────────────────────────
# Find the template VM ID by name on the clone node
@@ -29,8 +24,7 @@ data "proxmox_virtual_environment_vms" "templates" {
resource "proxmox_virtual_environment_vm" "vm" {
name = var.hostname
bios = "ovmf"
vm_id = local.vm_id
vm_id = var.vm_id
node_name = var.target_node
description = "Provisioned by mk-labs pipeline on ${timestamp()}"
@@ -65,7 +59,7 @@ resource "proxmox_virtual_environment_vm" "vm" {
network_device {
bridge = var.bridge
model = "virtio"
# vlan_id = var.vlan_id
vlan_id = var.vlan_id
}
# VM stays STOPPED after clone.

View File

@@ -1,6 +1,6 @@
output "vm_id" {
description = "Proxmox VM ID of the created VM."
value = proxmox_virtual_environment_vm.vm.vm_id
value = var.vm_id
}
output "mac_address" {

View File

@@ -1,13 +1,11 @@
# Copy this file to terraform.tfvars and fill in the values.
# terraform.tfvars is in .gitignore — never commit secrets.
proxmox_api_url = "https://fantasyland.mk-labs.net:8006"
proxmox_api_token = "terraform@pve!terraform-token=your-token-secret-here"
# These values come from n8n via -var flags at runtime:
# All values come from n8n via -var flags at runtime.
# Secrets are stored in n8n Global Constants — no terraform.tfvars file needed.
#
# vm_id = 71200
# hostname = "test-vm"
# ip_address = "10.1.71.100"
# ip_address = "10.1.71.200"
# target_node = "fantasyland"
# template_name = "ubuntu-24.04-small"
# datastore = "liberty-tree"
# vlan_id = 71
# proxmox_api_url = "https://fantasyland.local.mk-labs.cloud:8006"
# proxmox_api_token = "terraform@pve!terraform-token=your-token-secret-here"

View File

@@ -2,7 +2,7 @@
variable "proxmox_api_url" {
type = string
description = "Proxmox API endpoint URL (e.g., https://fantasyland.local.mk-labs.cloud:8006)"
description = "Proxmox API endpoint URL (e.g., https://fantasyland.mk-labs.net:8006)"
}
variable "proxmox_api_token" {
@@ -13,6 +13,11 @@ variable "proxmox_api_token" {
# ─── VM Identity ─────────────────────────────────────────────────────────────
variable "vm_id" {
type = number
description = "Proxmox VM ID. Computed by n8n from IP: {third_octet}{fourth_octet:03d} (e.g., 10.1.71.200 → 71200)."
}
variable "hostname" {
type = string
description = "VM hostname. Used as the Proxmox VM name and cloud-init hostname."
@@ -26,7 +31,7 @@ variable "ip_address" {
variable "dns_servers" {
type = list(string)
description = "DNS servers for the VM."
default = ["10.1.71.1"]
default = ["10.1.71.102", "10.1.71.1"]
}
variable "search_domain" {