Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reserve IP addresses for supernodes #4

Merged
merged 5 commits into from
Jan 20, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.vagrant/

.terraform/
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"
}
30 changes: 30 additions & 0 deletions terraform/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

mraerino marked this conversation as resolved.
Show resolved Hide resolved
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"
}