Create NetBox sites rather than requiring them to pre-exist
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:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user