From 36eaa727ab585c4c7e8ac6a1e672c1f073e1e188 Mon Sep 17 00:00:00 2001 From: Guy Godfroy Date: Sun, 15 Mar 2026 14:05:40 +0100 Subject: [PATCH] Refactor network module to accept free-form config maps Replace hypervisor_parent/witness_parent strings with hypervisor_config and witness_config map(string) variables, matching the pattern already used by the storage module. incus_networks in the root module is updated from map(number) to map(object) carrying type and the two config maps. Co-Authored-By: Claude Sonnet 4.6 --- incus/modules/network/main.tf | 8 ++------ incus/modules/network/variables.tf | 12 ++++++------ incus/network.auto.tfvars | 10 +++++++++- incus/network.tf | 13 ++++++++----- incus/variables.tf | 6 +++++- 5 files changed, 30 insertions(+), 19 deletions(-) diff --git a/incus/modules/network/main.tf b/incus/modules/network/main.tf index 6e77062..8a9fc2b 100644 --- a/incus/modules/network/main.tf +++ b/incus/modules/network/main.tf @@ -11,9 +11,7 @@ resource "incus_network" "hypervisor" { name = var.name target = each.key type = var.type - config = { - "parent" = var.hypervisor_parent - } + config = var.hypervisor_config } resource "incus_network" "witness" { @@ -21,9 +19,7 @@ resource "incus_network" "witness" { name = var.name target = each.key type = var.type - config = { - "parent" = var.witness_parent - } + config = var.witness_config } resource "incus_network" "this" { diff --git a/incus/modules/network/variables.tf b/incus/modules/network/variables.tf index a5d5b40..36aebc4 100644 --- a/incus/modules/network/variables.tf +++ b/incus/modules/network/variables.tf @@ -15,12 +15,12 @@ variable "witnesses" { type = set(string) } -variable "hypervisor_parent" { - type = string - default = "br0" +variable "hypervisor_config" { + type = map(string) + default = {} } -variable "witness_parent" { - type = string - default = "dummy0" +variable "witness_config" { + type = map(string) + default = {} } diff --git a/incus/network.auto.tfvars b/incus/network.auto.tfvars index 8c529b3..55df2f7 100644 --- a/incus/network.auto.tfvars +++ b/incus/network.auto.tfvars @@ -1,3 +1,11 @@ incus_networks = { - "main" = 0 + "main" = { + type = "physical" + hypervisor_config = { + "parent" = "br0" + } + witness_config = { + "parent" = "dummy0" + } + } } diff --git a/incus/network.tf b/incus/network.tf index c14aaf6..b9bde5e 100644 --- a/incus/network.tf +++ b/incus/network.tf @@ -1,8 +1,11 @@ module "network" { - source = "./modules/network" - for_each = var.incus_networks - name = each.key - hypervisors = toset(keys(var.incus_hypervisors)) - witnesses = toset(keys(var.incus_witnesses)) + source = "./modules/network" + for_each = var.incus_networks + name = each.key + type = each.value.type + hypervisors = toset(keys(var.incus_hypervisors)) + witnesses = toset(keys(var.incus_witnesses)) + hypervisor_config = each.value.hypervisor_config + witness_config = each.value.witness_config } diff --git a/incus/variables.tf b/incus/variables.tf index 6aa0517..eb18cc1 100644 --- a/incus/variables.tf +++ b/incus/variables.tf @@ -13,7 +13,11 @@ variable "incus_token" { } variable "incus_networks" { - type = map(number) + type = map(object({ + type = string + hypervisor_config = map(string) + witness_config = map(string) + })) } variable "incus_storage_pools" {