Skip to content

Resource: proxmox_virtual_environment_harule

Warning

Deprecated: Use proxmox_harule instead. This resource will be removed in v1.0.

Manages a High Availability rule in a Proxmox VE cluster (PVE 9+). HA rules replace the legacy HA groups and provide node affinity and resource affinity capabilities.

Warning

Note: This resource requires Proxmox VE 9.0 or later. In PVE 9, HA groups have been replaced by HA rules, which provide node affinity and resource affinity capabilities. For PVE 8 and earlier, use proxmox_virtual_environment_hagroup instead.

Example Usage

# Node Affinity Rule: assign VMs to preferred nodes with priorities.
# Non-strict rules allow failover to other nodes; strict rules do not.
resource "proxmox_virtual_environment_harule" "prefer_node1" {
  rule      = "prefer-node1"
  type      = "node-affinity"
  comment   = "Prefer node1 for these VMs"
  resources = ["vm:100", "vm:101"]

  nodes = {
    node1 = 2 # Higher priority
    node2 = 1
    node3 = 1
  }

  strict = false
}

# Resource Affinity Rule (Positive): keep resources together on the same node.
resource "proxmox_virtual_environment_harule" "keep_together" {
  rule      = "db-cluster-together"
  type      = "resource-affinity"
  comment   = "Keep database replicas on the same node"
  resources = ["vm:200", "vm:201"]
  affinity  = "positive"
}

# Resource Affinity Rule (Negative / Anti-Affinity): keep resources on
# separate nodes for high availability.
resource "proxmox_virtual_environment_harule" "keep_apart" {
  rule      = "db-cluster-apart"
  type      = "resource-affinity"
  comment   = "Spread database replicas across nodes"
  resources = ["vm:200", "vm:201", "vm:202"]
  affinity  = "negative"
}

Schema

Required

  • resources (Set of String) The set of HA resource IDs that this rule applies to (e.g. vm:100, ct:101). The resources must already be managed by HA.
  • rule (String) The identifier of the High Availability rule to manage.
  • type (String) The HA rule type. Must be node-affinity or resource-affinity.

Optional

  • affinity (String) The resource affinity type (resource-affinity only). positive keeps resources on the same node, negative keeps them on separate nodes.
  • comment (String) The comment associated with this rule.
  • disable (Boolean) Whether the HA rule is disabled. Defaults to false.
  • nodes (Map of Number) The member nodes for this rule (node-affinity only). They are provided as a map, where the keys are the node names and the values represent their priority: integers for known priorities or null for unset priorities.
  • strict (Boolean) Whether the node affinity rule is strict (node-affinity only). When strict, resources cannot run on nodes not listed. Defaults to false.

Read-Only

  • id (String) The unique identifier of this resource.

Import

Import is supported using the following syntax:

#!/usr/bin/env sh
# HA rules can be imported using their name, e.g.:
terraform import proxmox_virtual_environment_harule.example prefer-node1