Skip to content

Commit

Permalink
Create tunnel resources (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
mraerino authored Jul 6, 2024
1 parent 6f3b47a commit 69844a3
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
6 changes: 6 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ locals {
}
}

resource "netbox_vpn_tunnel_group" "sites" {
name = "site-tunnels"
}

module "device" {
for_each = local.devices

Expand All @@ -26,4 +30,6 @@ module "device" {
)

tunnel_prefix_role_id = data.netbox_ipam_role.transfer.id

tunnel_group_id = netbox_vpn_tunnel_group.sites.id
}
20 changes: 20 additions & 0 deletions modules/device/tunnel.tf
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,23 @@ resource "netbox_ip_address" "local_tunnel_address_v6" {
description = "Peer address of ${var.name} for ${each.key}"
tenant_id = var.tenant_id
}

resource "netbox_vpn_tunnel" "core" {
for_each = { for i, name in var.tunnel_peer_names : name => i }

name = "${each.key}-${var.name}"
encapsulation = "gre"
status = "active"
description = "Site tunnel from ${each.key} to ${local.location}"

tunnel_group_id = var.tunnel_group_id
}

resource "netbox_vpn_tunnel_termination" "site" {
for_each = netbox_vpn_tunnel.core

tunnel_id = each.value.id
role = "peer"

device_interface_id = netbox_device_interface.tunnels[each.key].id
}
5 changes: 5 additions & 0 deletions modules/device/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ variable "tunnel_peer_names" {
description = "names of tunnel peers"
}

variable "tunnel_group_id" {
type = number
description = "ID of the tunnel group to create tunnels in"
}

variable "tunnel_prefix_v4_id" {
type = number
description = "Netbox ID of prefix (v4) to create tunnel prefix in"
Expand Down

0 comments on commit 69844a3

Please sign in to comment.