Skip to content

Commit

Permalink
Reserve IP addresses for supernodes (#4)
Browse files Browse the repository at this point in the history
In order to create new supernodes on our own infrastructure, we first
need to assign IP address prefixes and addresses for each supernode.

---------

Co-authored-by: Mic Szillat <[email protected]>
  • Loading branch information
mraerino and nomaster authored Jan 20, 2024
1 parent 375975c commit 28997f1
Show file tree
Hide file tree
Showing 11 changed files with 198 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.vagrant/

.terraform/
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Supernodes

## IP Addressing

- Assign a single IPv4 address per supernode
- management IP to reach the machine
- NAT IP to route client traffic
- assigned from our `/24` aggregate
- Assign a `/64` loopback prefix for all supernodes in a domain
- each supernode gets one IP from this prefix
37 changes: 37 additions & 0 deletions terraform/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions terraform/main.tf
Original file line number Diff line number Diff line change
@@ -1,2 +1,14 @@
resource "null_resource" "test" {
}

module "supernode" {
count = var.supernode_count

source = "./modules/supernode"

supernode_name = "${var.domain_name}_${count.index}"

prefix_ipv4_id = data.netbox_prefix.primary_ipv4.id
prefix_ipv6_id = netbox_available_prefix.domain_ipv6.id
loopback_prefix_ipv6_id = netbox_prefix.loopback_ipv6.id
}
7 changes: 7 additions & 0 deletions terraform/modules/supernode/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
terraform {
required_providers {
netbox = {
source = "e-breuninger/netbox"
}
}
}
20 changes: 20 additions & 0 deletions terraform/modules/supernode/primary-ipv4.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
resource "netbox_available_prefix" "primary_ipv4" {
description = "Primary Address ${var.supernode_name}"
status = "active"

parent_prefix_id = var.prefix_ipv4_id
prefix_length = 32

tags = toset(var.tags)
}

resource "netbox_available_ip_address" "primary_ipv4" {
status = "active"

description = "Primary Address ${var.supernode_name}"

prefix_id = netbox_available_prefix.primary_ipv4.id
// TODO: set interface_id

tags = toset(var.tags)
}
20 changes: 20 additions & 0 deletions terraform/modules/supernode/primary-ipv6.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
resource "netbox_available_prefix" "primary_ipv6" {
description = "Primary Address ${var.supernode_name}"
status = "active"

parent_prefix_id = var.loopback_prefix_ipv6_id
prefix_length = 128

tags = toset(var.tags)
}

resource "netbox_available_ip_address" "primary_ipv6" {
status = "active"

description = "Primary Address ${var.supernode_name}"

prefix_id = netbox_available_prefix.primary_ipv6.id
// TODO: set interface_id

tags = toset(var.tags)
}
25 changes: 25 additions & 0 deletions terraform/modules/supernode/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
variable "supernode_name" {
type = string
description = "Name of the Supernode"
}

variable "tags" {
type = list(string)
description = "Tags for the resources"
default = []
}

variable "prefix_ipv4_id" {
type = string
description = "ID of the Supernode IPv4 prefix"
}

variable "prefix_ipv6_id" {
type = string
description = "ID of the Supernode IPv6 prefix"
}

variable "loopback_prefix_ipv6_id" {
type = string
description = "ID of the Loopback Supernode IPv6 prefix"
}
24 changes: 24 additions & 0 deletions terraform/primary-prefixes.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
data "netbox_prefix" "primary_ipv4" {
prefix = var.primary_prefix_ipv4
}

data "netbox_prefix" "primary_ipv6" {
prefix = var.primary_prefix_ipv6
}

resource "netbox_available_prefix" "domain_ipv6" {
description = "Supernode IPv6 addresses ${var.domain_name}"
prefix_length = 56
status = "reserved"
parent_prefix_id = data.netbox_prefix.primary_ipv6.id

tags = toset(var.tags)
}

resource "netbox_prefix" "loopback_ipv6" {
prefix = cidrsubnet(netbox_available_prefix.domain_ipv6.prefix, 8, 0)
description = "Supernode IPv6 loopback addresses ${var.domain_name}"
status = "reserved"

tags = toset(var.tags)
}
12 changes: 12 additions & 0 deletions terraform/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
terraform {
required_providers {
netbox = {
source = "e-breuninger/netbox"
version = "3.7.6"
}
}
}

provider "netbox" {
server_url = "https://netbox.freifunk-duesseldorf.de"
}
29 changes: 29 additions & 0 deletions terraform/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
variable "domain_name" {
type = string
description = "Name of the supernode domain"
default = "dev"
}

variable "tags" {
type = list(string)
description = "Tags for the resources"
default = []
}

variable "supernode_count" {
type = number
description = "Number of supernodes for this domain"
default = 2
}

variable "primary_prefix_ipv4" {
type = string
description = "Prefix to issue primary IPv4 addresses from"
default = "45.151.166.0/24"
}

variable "primary_prefix_ipv6" {
type = string
description = "Prefix to issue primary IPv6 addresses from"
default = "2001:678:b7c::/48"
}

0 comments on commit 28997f1

Please sign in to comment.