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 <noreply@anthropic.com>
This commit is contained in:
2026-03-15 14:05:40 +01:00
parent 6b53db3ad9
commit 36eaa727ab
5 changed files with 30 additions and 19 deletions

View File

@@ -11,9 +11,7 @@ resource "incus_network" "hypervisor" {
name = var.name name = var.name
target = each.key target = each.key
type = var.type type = var.type
config = { config = var.hypervisor_config
"parent" = var.hypervisor_parent
}
} }
resource "incus_network" "witness" { resource "incus_network" "witness" {
@@ -21,9 +19,7 @@ resource "incus_network" "witness" {
name = var.name name = var.name
target = each.key target = each.key
type = var.type type = var.type
config = { config = var.witness_config
"parent" = var.witness_parent
}
} }
resource "incus_network" "this" { resource "incus_network" "this" {

View File

@@ -15,12 +15,12 @@ variable "witnesses" {
type = set(string) type = set(string)
} }
variable "hypervisor_parent" { variable "hypervisor_config" {
type = string type = map(string)
default = "br0" default = {}
} }
variable "witness_parent" { variable "witness_config" {
type = string type = map(string)
default = "dummy0" default = {}
} }

View File

@@ -1,3 +1,11 @@
incus_networks = { incus_networks = {
"main" = 0 "main" = {
type = "physical"
hypervisor_config = {
"parent" = "br0"
}
witness_config = {
"parent" = "dummy0"
}
}
} }

View File

@@ -1,8 +1,11 @@
module "network" { module "network" {
source = "./modules/network" source = "./modules/network"
for_each = var.incus_networks for_each = var.incus_networks
name = each.key name = each.key
hypervisors = toset(keys(var.incus_hypervisors)) type = each.value.type
witnesses = toset(keys(var.incus_witnesses)) hypervisors = toset(keys(var.incus_hypervisors))
witnesses = toset(keys(var.incus_witnesses))
hypervisor_config = each.value.hypervisor_config
witness_config = each.value.witness_config
} }

View File

@@ -13,7 +13,11 @@ variable "incus_token" {
} }
variable "incus_networks" { variable "incus_networks" {
type = map(number) type = map(object({
type = string
hypervisor_config = map(string)
witness_config = map(string)
}))
} }
variable "incus_storage_pools" { variable "incus_storage_pools" {