From 4d403bf5d4e4d98f8d4b4810fb0ad3cf18a97f60 Mon Sep 17 00:00:00 2001 From: Marcus Weiner Date: Mon, 8 Jul 2024 00:07:02 +0200 Subject: [PATCH] Manage static addresses used for GRE --- import-dnat.tf | 34 ++++++++++++++++++++++++++++++++++ modules/device/variables.tf | 6 ++++++ modules/device/wan.tf | 20 ++++++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 import-dnat.tf create mode 100644 modules/device/wan.tf diff --git a/import-dnat.tf b/import-dnat.tf new file mode 100644 index 0000000..3070e8f --- /dev/null +++ b/import-dnat.tf @@ -0,0 +1,34 @@ +import { + to = module.device["R9"].netbox_ip_address.gre_dnat + id = 261 +} + +import { + to = module.device["R10"].netbox_ip_address.gre_dnat + id = 294 +} + +import { + to = module.device["R14"].netbox_ip_address.gre_dnat + id = 331 +} + +import { + to = module.device["R15"].netbox_ip_address.gre_dnat + id = 559 +} + +import { + to = module.device["R18"].netbox_ip_address.gre_dnat + id = 643 +} + +import { + to = module.device["R19"].netbox_ip_address.gre_dnat + id = 512 +} + +import { + to = module.device["R20"].netbox_ip_address.gre_dnat + id = 727 +} diff --git a/modules/device/variables.tf b/modules/device/variables.tf index 90b8edd..c038ba4 100644 --- a/modules/device/variables.tf +++ b/modules/device/variables.tf @@ -77,3 +77,9 @@ variable "tenant_id" { description = "NetBox tenant ID to use for all resources" default = 1 } + +variable "gre_dnat_ip" { + type = string + description = "Private IP addressed used to receive GRE packets from the CPE" + default = "192.168.178.10/24" +} diff --git a/modules/device/wan.tf b/modules/device/wan.tf new file mode 100644 index 0000000..4d82fcb --- /dev/null +++ b/modules/device/wan.tf @@ -0,0 +1,20 @@ +data "netbox_device_interfaces" "wan" { + filter { + name = "device_id" + value = var.device_id + } + + filter { + name = "name" + value = "eth2" + } +} + +resource "netbox_ip_address" "gre_dnat" { + vrf_id = netbox_vrf.local.id + ip_address = var.gre_dnat_ip + status = "active" + device_interface_id = one(data.netbox_device_interfaces.wan.interfaces).id + + description = "Static Uplink IP (for GRE forwarding) on ${local.location}" +}