diff --git a/proxmox/README.md b/proxmox/README.md index b16ed68..325dca5 100644 --- a/proxmox/README.md +++ b/proxmox/README.md @@ -1,6 +1,6 @@ # Proxmox -It was tested on Proxmox version 7.4-3 +It was tested on Proxmox version 8.2 Local utilities @@ -94,9 +94,27 @@ machine: First we need to define our cluster: ```hcl -proxmox_host = "node1.example.com" +# Proxmox API host +proxmox_host = "node1.example.com" -vpc_main_cidr = "172.16.0.0/24" +# Local proxmox subnets +vpc_main_cidr = ["172.16.0.0/24", "fd60:172:16::/64"] + +# Node configuration +nodes = { + "node1" = { + storage = "data", + ip4 = "1.1.0.1" + ip6 = "2001:1:2:1::/64", + gw6 = "2001:1:2:1::64", + }, + "node2" = { + storage = "data", + ip4 = "1.1.0.2" + ip6 = "2001:1:2:2::/64", + gw6 = "2001:1:2:2::64", + }, +} # We will create one control-plane node on the Proxmox node `node1` (count = 1) controlplane = { diff --git a/proxmox/common.tf b/proxmox/common.tf index 57b4066..576b411 100644 --- a/proxmox/common.tf +++ b/proxmox/common.tf @@ -1,16 +1,4 @@ -locals { - cpu_numa = { - for k, v in var.nodes : k => [for i in lookup(v, "cpu", "") : - flatten([for r in split(",", i) : (strcontains(r, "-") ? range(split("-", r)[0], split("-", r)[1] + 1, 1) : [r])]) - ] - } - - cpus = { for k, v in local.cpu_numa : k => - flatten([for numa in v : flatten([for r in range(length(numa) / 2) : [numa[r], numa[r + length(numa) / 2]]])]) - } -} - data "proxmox_virtual_environment_node" "node" { for_each = { for inx, zone in local.zones : zone => inx if lookup(try(var.instances[zone], {}), "enabled", false) } node_name = each.key diff --git a/proxmox/cpuaffinity/variables.tf b/proxmox/cpuaffinity/variables.tf index a73355d..f770079 100644 --- a/proxmox/cpuaffinity/variables.tf +++ b/proxmox/cpuaffinity/variables.tf @@ -29,7 +29,7 @@ locals { flatten([flatten([for r in range(length(v) / 2) : [v[r], v[r + length(v) / 2]]])]) ] - shift = var.shift * length(local.cpus[0]) + shift = var.shift * length(try(local.cpus[0], [])) vm_arch = { for k in flatten([ for inx in range(var.vms) : { diff --git a/proxmox/instances-db.tf b/proxmox/instances-db.tf index fbac78e..d595439 100644 --- a/proxmox/instances-db.tf +++ b/proxmox/instances-db.tf @@ -32,7 +32,7 @@ module "db_affinity" { } if lookup(try(var.instances[zone], {}), "db_count", 0) > 0 } source = "./cpuaffinity" - cpu_affinity = var.nodes[each.value.zone].cpu + cpu_affinity = length(lookup(try(var.nodes[each.value.zone], {}), "cpu", [])) > 0 ? var.nodes[each.value.zone].cpu : ["0-${2 * data.proxmox_virtual_environment_node.node[each.value.zone].cpu_count * data.proxmox_virtual_environment_node.node[each.value.zone].cpu_sockets - 1}"] vms = each.value.vms cpus = lookup(try(var.instances[each.value.zone], {}), "db_cpu", 1) # shift = length(var.nodes[each.value.zone].cpu) - 1 @@ -96,7 +96,7 @@ resource "proxmox_virtual_environment_vm" "db" { cpu { architecture = "x86_64" cores = each.value.cpu - affinity = join(",", module.db_affinity[each.value.zone].arch[each.value.inx].cpus) + affinity = length(lookup(try(var.nodes[each.value.zone], {}), "cpu", [])) > 0 ? join(",", module.db_affinity[each.value.zone].arch[each.value.inx].cpus) : null sockets = 1 numa = true type = "host" diff --git a/proxmox/instances-web.tf b/proxmox/instances-web.tf index a0bc160..b831a8d 100644 --- a/proxmox/instances-web.tf +++ b/proxmox/instances-web.tf @@ -32,7 +32,7 @@ module "web_affinity" { } if lookup(try(var.instances[zone], {}), "web_count", 0) > 0 } source = "./cpuaffinity" - cpu_affinity = var.nodes[each.value.zone].cpu + cpu_affinity = length(lookup(try(var.nodes[each.value.zone], {}), "cpu", [])) > 0 ? var.nodes[each.value.zone].cpu : ["0-${2 * data.proxmox_virtual_environment_node.node[each.value.zone].cpu_count * data.proxmox_virtual_environment_node.node[each.value.zone].cpu_sockets - 1}"] vms = each.value.vms cpus = lookup(try(var.instances[each.value.zone], {}), "web_cpu", 1) } @@ -117,7 +117,7 @@ resource "proxmox_virtual_environment_vm" "web" { cpu { architecture = "x86_64" cores = each.value.cpu - affinity = join(",", module.web_affinity[each.value.zone].arch[each.value.inx].cpus) + affinity = length(lookup(try(var.nodes[each.value.zone], {}), "cpu", [])) > 0 ? join(",", module.web_affinity[each.value.zone].arch[each.value.inx].cpus) : null sockets = 1 numa = true type = "host" @@ -132,7 +132,7 @@ resource "proxmox_virtual_environment_vm" "web" { device = "numa${index(keys(module.web_affinity[each.value.zone].arch[each.value.inx].numa), idx)}" cpus = "${index(keys(module.web_affinity[each.value.zone].arch[each.value.inx].numa), idx) * (each.value.cpu / length(module.web_affinity[each.value.zone].arch[each.value.inx].numa))}-${(index(keys(module.web_affinity[each.value.zone].arch[each.value.inx].numa), idx) + 1) * (each.value.cpu / length(module.web_affinity[each.value.zone].arch[each.value.inx].numa)) - 1}" mem = each.value.mem / length(module.web_affinity[each.value.zone].arch[each.value.inx].numa) - } } + } if length(lookup(try(var.nodes[each.value.zone], {}), "cpu", [])) > 0 } content { device = numa.value.device cpus = numa.value.cpus diff --git a/proxmox/instances-worker.tf b/proxmox/instances-worker.tf index 2a367b3..52c68bc 100644 --- a/proxmox/instances-worker.tf +++ b/proxmox/instances-worker.tf @@ -32,7 +32,7 @@ module "worker_affinity" { } if lookup(try(var.instances[zone], {}), "worker_count", 0) > 0 } source = "./cpuaffinity" - cpu_affinity = var.nodes[each.value.zone].cpu + cpu_affinity = length(lookup(try(var.nodes[each.value.zone], {}), "cpu", [])) > 0 ? var.nodes[each.value.zone].cpu : ["0-${2 * data.proxmox_virtual_environment_node.node[each.value.zone].cpu_count * data.proxmox_virtual_environment_node.node[each.value.zone].cpu_sockets - 1}"] vms = each.value.vms cpus = lookup(try(var.instances[each.value.zone], {}), "worker_cpu", 1) } @@ -95,7 +95,7 @@ resource "proxmox_virtual_environment_vm" "worker" { cpu { architecture = "x86_64" cores = each.value.cpu - affinity = join(",", module.worker_affinity[each.value.zone].arch[each.value.inx].cpus) + affinity = length(lookup(try(var.nodes[each.value.zone], {}), "cpu", [])) > 0 ? join(",", module.worker_affinity[each.value.zone].arch[each.value.inx].cpus) : null sockets = 1 numa = true type = "host" diff --git a/proxmox/variables.tf b/proxmox/variables.tf index b0311ec..e7dd764 100644 --- a/proxmox/variables.tf +++ b/proxmox/variables.tf @@ -18,7 +18,7 @@ variable "network_shift" { } variable "vpc_main_cidr" { - description = "Local proxmox subnet" + description = "Local proxmox subnets" type = list(string) default = ["172.16.0.0/24", "fd60:172:16::/64"] } @@ -53,17 +53,17 @@ variable "nodes" { default = { "hvm-1" = { storage = "data", - cpu = ["0-3,16-19", "4-7,20-23", "8-11,24-27", "12-15,28-31"], - ip4 = "1.1.0.1" - ip6 = "2001:1:2:1::/64", - gw6 = "2001:1:2:1::64", + # cpu = ["0-3,16-19", "4-7,20-23", "8-11,24-27", "12-15,28-31"], + ip4 = "1.1.0.1" + ip6 = "2001:1:2:1::/64", + gw6 = "2001:1:2:1::64", }, "hvm-2" = { storage = "data", - cpu = ["0-3,16-19", "4-7,20-23", "8-11,24-27", "12-15,28-31"], - ip4 = "1.1.0.2" - ip6 = "2001:1:2:2::/64", - gw6 = "2001:1:2:2::64", + # cpu = ["0-3,16-19", "4-7,20-23", "8-11,24-27", "12-15,28-31"], + ip4 = "1.1.0.2" + ip6 = "2001:1:2:2::/64", + gw6 = "2001:1:2:2::64", }, } }