diff --git a/modules/device/networks.tf b/modules/device/networks.tf new file mode 100644 index 0000000..d7fe2ef --- /dev/null +++ b/modules/device/networks.tf @@ -0,0 +1,29 @@ +resource "netbox_vrf" "local" { + name = var.name +} + +resource "netbox_prefix" "local_v4" { + vrf_id = netbox_vrf.local.id + prefix = var.client_prefix_v4 + status = "active" +} + +resource "netbox_prefix" "networks_v4" { + for_each = netbox_vlan.networks + + vrf_id = netbox_vrf.local.id + prefix = cidrsubnet(var.client_prefix_v4, 8, each.value.vid) + + status = "active" + description = "'${each.value.name}' network for ${var.name}" +} + +resource "netbox_prefix" "networks_v6" { + for_each = netbox_vlan.networks + + vrf_id = netbox_vrf.local.id + prefix = cidrsubnet(netbox_available_prefix.site_v6.prefix, 8, each.value.vid) + + status = "active" + description = "'${each.value.name}' network for ${var.name}" +} diff --git a/modules/device/variables.tf b/modules/device/variables.tf index 20f1c63..29f9c00 100644 --- a/modules/device/variables.tf +++ b/modules/device/variables.tf @@ -55,3 +55,9 @@ variable "site_id" { type = number description = "Netbox ID of the site" } + +variable "client_prefix_v4" { + type = string + description = "private network to assign client subnets from" + default = "10.0.0.0/8" +}