Skip to content

feat: add proxmox_node_status data source - #1510

Open
cgoolsby wants to merge 1 commit into
Telmate:masterfrom
cgoolsby:master
Open

feat: add proxmox_node_status data source#1510
cgoolsby wants to merge 1 commit into
Telmate:masterfrom
cgoolsby:master

Conversation

@cgoolsby

@cgoolsby cgoolsby commented Apr 13, 2026

Copy link
Copy Markdown

Summary

  • Adds a new proxmox_node_status data source that queries the Proxmox /nodes API endpoint
  • Exposes whether a node is in HA maintenance mode via the maintenance boolean attribute
  • Also surfaces status, uptime, cpu, mem_used, and mem_total for convenience

Motivation

The primary use case is excluding nodes in maintenance mode from workload placement. Without this data source, there is no way to query node-level status from within Terraform, leaving users no option but to manually check the Proxmox UI before running terraform apply.

Usage

Prevent deploying onto a node in maintenance mode:

data "proxmox_node_status" "pve1" {
  node = "pve1"
}

resource "proxmox_vm_qemu" "app" {
  target_node = "pve1"

  lifecycle {
    precondition {
      condition     = !data.proxmox_node_status.pve1.maintenance
      error_message = "Node pve1 is in maintenance mode — refusing to deploy."
    }
  }
}

Skip resources on a maintenance node:

resource "proxmox_vm_qemu" "app" {
  count       = data.proxmox_node_status.pve1.maintenance ? 0 : 1
  target_node = "pve1"
}

Notes

  • No changes to proxmox-api-go required — uses the existing GetNodeList() method
  • The maintenance field is absent from the API response for normal nodes and safely defaults to false; Proxmox sends a numeric 1 when the HA manager places a node into maintenance mode
  • maintenance and status are kept as separate attributes because they are orthogonal: a node can be online and in maintenance simultaneously

Test plan

  • go build ./... passes
  • go vet ./... passes
  • staticcheck ./... passes
  • go test -race -vet=off ./... passes
  • Verify maintenance = true when node is in maintenance mode in Proxmox web UI
  • Verify maintenance = false for a normal online node

Adds a new data source that queries the Proxmox /nodes API endpoint
to expose per-node status information, including whether a node has
been placed into maintenance mode by the HA manager.

Attributes returned:
- status (string): "online" or "offline"
- maintenance (bool): true when the node is in HA maintenance mode
- uptime (int): node uptime in seconds
- cpu (float): CPU utilization fraction
- mem_used (int): memory used in bytes
- mem_total (int): total memory in bytes

The primary use case is excluding nodes in maintenance mode from
workload placement. For example, using a precondition to prevent
deploying VMs onto a node that is draining:

  data "proxmox_node_status" "pve1" {
    node = "pve1"
  }

  resource "proxmox_vm_qemu" "app" {
    lifecycle {
      precondition {
        condition     = !data.proxmox_node_status.pve1.maintenance
        error_message = "Node pve1 is in maintenance mode."
      }
    }
  }

maintenance and status are kept as separate attributes because they
are orthogonal: a node can be online and in maintenance simultaneously.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant