Files
terraform-netbox/modules/netbox/networks.tf
unkin-agent a3984bf0cd
ci/woodpecker/pr/plan Pipeline failed
ci/woodpecker/pr/pre-commit Pipeline was successful
Take global object ids from the global unit
A per-site data-source lookup cannot resolve a global object before the global
unit has applied it, which deadlocks the first plan. Pass device-type, device
role and dhcp IPAM role ids as dependency outputs instead, mocked for plan.
2026-10-03 18:39:03 +10:00

58 lines
1.7 KiB
Terraform

locals {
subnet_prefix = { for k, v in var.subnets : k => v.prefix }
}
# One VLAN group scoped to this site, so the same VID may exist in another site.
resource "netbox_vlan_group" "this" {
name = "${var.site_slug} vlans"
slug = "${var.site_slug}-vlans"
scope_type = "dcim.site"
scope_id = tonumber(netbox_site.this.id)
vid_ranges = var.vlans.vid_ranges
}
resource "netbox_vlan" "this" {
for_each = { for v in var.vlans.vlans : v.vid => v }
name = each.value.name
vid = each.value.vid
site_id = tonumber(netbox_site.this.id)
group_id = tonumber(netbox_vlan_group.this.id)
status = "active"
description = each.value.description
}
# Network profiles: the interfaces a logical host should have. Published as a
# config context so the UI reads them from the NetBox API rather than from git.
resource "netbox_config_context" "network_profile" {
for_each = var.network_profiles
name = "network-profile:${each.key}"
description = each.value.description
weight = each.value.weight
sites = [tonumber(netbox_site.this.id)]
roles = [for r in each.value.roles : var.device_role_ids[r]]
data = jsonencode({
network_profile = {
name = each.key
interfaces = [
for i in each.value.interfaces : {
name = i.name
vlan = i.vlan
subnet = i.subnet
prefix = local.subnet_prefix[i.subnet]
subinterfaces = [
for s in i.subinterfaces : {
name = s.name
vlan = s.vlan
subnet = s.subnet
prefix = s.subnet != null ? local.subnet_prefix[s.subnet] : null
}
]
}
]
}
})
}