Extract network resources into reusable modules/network module

Moves the three incus_network resources into a dedicated module called
once per entry in var.incus_networks. State was migrated imperatively
via `terraform state mv` because lxc/incus v1.0.2 does not implement
ResourceWithMoveState, making declarative moved blocks unsupported.
Plan confirms zero creates/destroys after migration.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-14 21:38:58 +01:00
parent 9b1aa393b3
commit a5ac26937b
5 changed files with 96 additions and 27 deletions

View File

@@ -1,28 +1,8 @@
resource "incus_network" "main_bridge" {
for_each = var.incus_hypervisors
name = "main"
target = each.key
type = "physical"
config = {
"parent" = "br0"
}
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))
}
resource "incus_network" "main_dummy" {
for_each = var.incus_witnesses
name = "main"
target = each.key
type = "physical"
config = {
"parent" = "dummy0"
}
}
resource "incus_network" "main" {
depends_on = [
incus_network.main_bridge,
incus_network.main_dummy
]
name = "main"
type = "physical"
}