Create NetBox sites rather than requiring them to pre-exist
ci/woodpecker/pr/plan Pipeline was successful
ci/woodpecker/pr/pre-commit Pipeline was successful

The syd1 site does not exist, so the site data source failed the plan.
Sites now follow the same declared-by-reference rule as device roles,
types and manufacturers.
This commit is contained in:
2026-10-03 15:41:38 +10:00
parent 4c9bfb0448
commit 380fcff20c
3 changed files with 14 additions and 4 deletions
+4
View File
@@ -27,6 +27,10 @@ ci/puppetdb_backfill.py # reality backfill generator
`make plan` / `make apply` reconcile the YAML against NetBox. State lives in
Consul under `infra/terraform/netbox/<region>/<dc>/state`.
Sites, device roles, device types and manufacturers are all declared by being
referenced: any slug a subnet or device names is created. A site that already
exists in NetBox must be imported, not re-created, since site names are unique.
## Subnet schema (`subnets/<name>.yaml`)
```yaml
+1 -1
View File
@@ -52,7 +52,7 @@ resource "netbox_device" "this" {
name = each.key
device_type_id = netbox_device_type.this[each.value.model_hint].id
role_id = netbox_device_role.this[each.value.role].id
site_id = tonumber(data.netbox_site.this[each.value.site].id)
site_id = tonumber(netbox_site.this[each.value.site].id)
status = each.value.pxe ? "staged" : "active"
platform_id = try(netbox_platform.this[each.value.provision.platform].id, null)
+9 -3
View File
@@ -28,9 +28,15 @@ locals {
}
}
data "netbox_site" "this" {
# Sites are declared by being referenced: every slug named by a subnet or a
# device is created, exactly as device roles, types and manufacturers are. A
# site that already exists in NetBox must be imported rather than re-created
# (NetBox site names are unique).
resource "netbox_site" "this" {
for_each = local.sites
slug = each.value
name = each.value
slug = each.value
}
# One tag per network so prefixes can be discovered by network membership.
@@ -47,7 +53,7 @@ resource "netbox_prefix" "this" {
prefix = each.value.prefix
status = "active"
description = each.value.description
site_id = each.value.site != null ? tonumber(data.netbox_site.this[each.value.site].id) : null
site_id = each.value.site != null ? tonumber(netbox_site.this[each.value.site].id) : null
tags = [for t in local.prefix_net_tags[each.key] : t]
depends_on = [netbox_tag.network]