From bf723fd13ee7b1e2124126234674281bec56fd26 Mon Sep 17 00:00:00 2001 From: Marcus Weiner Date: Sat, 23 Mar 2024 19:33:40 +0100 Subject: [PATCH] Create local networks --- modules/device/networks.tf | 29 +++++++++++++++++++++++++++++ modules/device/variables.tf | 6 ++++++ 2 files changed, 35 insertions(+) create mode 100644 modules/device/networks.tf 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" +}