Skip to content

Commit f44e677

Browse files
committed
implement pfsense firewall routing
1 parent ae8f421 commit f44e677

4 files changed

Lines changed: 37 additions & 46 deletions

File tree

modules/connectivity-regional/2-network.tf

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,51 +2,36 @@
22
## NETWORKS ##
33
##############
44

5-
# will get auto assigned a free range from the network area (needs to be, because for a public ip it needs to be routed)
6-
resource "stackit_network" "wan" {
5+
# will get auto assigned a free range from the network area
6+
resource "stackit_network" "hub" {
77
project_id = stackit_resourcemanager_project.this.project_id
8-
name = "wan"
9-
#ipv4_nameservers = ["208.67.222.222", "9.9.9.9"] provider bug
10-
routed = true
11-
12-
depends_on = [stackit_network.lan]
13-
}
14-
15-
# this is not used, because it is not routed (not reachable by other projects)
16-
# the wan interface actually handles the internal and external traffic
17-
# actually lan should be reachable internally and wan not
18-
resource "stackit_network" "lan" {
19-
project_id = stackit_resourcemanager_project.this.project_id
20-
name = "lan"
21-
ipv4_nameservers = ["208.67.222.222", "9.9.9.9"]
22-
ipv4_prefix = var.vnet_range
23-
ipv4_gateway = var.firewall_ip
24-
routed = false
8+
name = "hub_network"
9+
routed = true
2510
}
2611

2712
################
2813
## INTERFACES ##
2914
################
3015

31-
# the firewall will see a private ip, because stackit handles NAT (public ip is not attached directly)
3216
resource "stackit_network_interface" "wan" {
17+
name = "vtnet0_wan"
3318
project_id = stackit_resourcemanager_project.this.project_id
34-
network_id = stackit_network.wan.network_id
19+
network_id = stackit_network.hub.network_id
3520
security = false
3621
}
3722

3823
resource "stackit_network_interface" "lan" {
24+
name = "vtnet1_lan"
3925
project_id = stackit_resourcemanager_project.this.project_id
40-
network_id = stackit_network.lan.network_id
41-
ipv4 = var.firewall_ip
26+
network_id = stackit_network.hub.network_id
4227
security = false
4328
}
4429

4530
###############
4631
## PUBLIC IP ##
4732
###############
4833

49-
resource "stackit_public_ip" "wan" {
34+
resource "stackit_public_ip" "wan-ip" {
5035
project_id = stackit_resourcemanager_project.this.project_id
5136
network_interface_id = stackit_network_interface.wan.network_interface_id
5237
}

modules/connectivity-regional/3-firewall.tf

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# }
1313
# }
1414

15-
resource "stackit_image" "pfsense" {
15+
resource "stackit_image" "pfsense_image" {
1616
project_id = stackit_resourcemanager_project.this.project_id
1717
name = "pfsense-2.7.2-amd64-image"
1818
local_file_path = "./pfsense.qcow2"
@@ -23,21 +23,21 @@ resource "stackit_image" "pfsense" {
2323
uefi = false
2424
}
2525

26-
# depends_on = [terraform_data.pfsense_image_file]
26+
# depends_on = [terraform_data.pfsense_image_file]
2727
}
2828

2929
############
3030
## VOLUME ##
3131
############
3232

33-
resource "stackit_volume" "pfsense" {
33+
resource "stackit_volume" "pfsense_vol" {
3434
project_id = stackit_resourcemanager_project.this.project_id
3535
name = "pfsense-2.7.2-root"
3636
availability_zone = var.firewall_zone
3737
size = 16
3838
performance_class = "storage_premium_perf4"
3939
source = {
40-
id = stackit_image.pfsense.image_id
40+
id = stackit_image.pfsense_image.image_id
4141
type = "image"
4242
}
4343
}
@@ -47,16 +47,16 @@ resource "stackit_volume" "pfsense" {
4747
############
4848

4949
# after rollout: https://docs.stackit.cloud/products/quick-deployments/pfsense-firewall/tutorials/configure-pfsense/
50-
resource "stackit_server" "pfsense" {
50+
resource "stackit_server" "pfsense_Server" {
5151
project_id = stackit_resourcemanager_project.this.project_id
5252
name = "pfSense"
5353
boot_volume = {
5454
source_type = "volume"
55-
source_id = stackit_volume.pfsense.volume_id
55+
source_id = stackit_volume.pfsense_vol.volume_id
5656
}
5757
availability_zone = var.firewall_zone
5858
machine_type = var.firewall_flavor
59-
59+
6060
network_interfaces = [
6161
stackit_network_interface.wan.network_interface_id, # vtnet0 = WAN
6262
stackit_network_interface.lan.network_interface_id # vtnet1 = LAN

modules/connectivity-regional/4-routes.tf

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,23 @@
22
## NETWORK AREA ROUTES ##
33
#########################
44

5-
# Default route: send all non-local traffic from the network area through pfSense
6-
# This enables project-to-internet and project-to-project routing via the firewall
7-
resource "stackit_network_area_route" "default" {
5+
resource "stackit_network_area_route" "rfc1918_10" {
86
organization_id = var.organization_id
97
network_area_id = var.network_area_id
10-
destination = {
11-
type = "cidrv4"
12-
value = "0.0.0.0/0"
13-
}
14-
next_hop = {
15-
type = "ipv4"
16-
value = stackit_network_interface.wan.ipv4
17-
}
8+
destination = { type = "cidrv4", value = "10.0.0.0/8" }
9+
next_hop = { type = "ipv4", value = stackit_network_interface.lan.ipv4 }
1810
}
11+
12+
resource "stackit_network_area_route" "rfc1918_172" {
13+
organization_id = var.organization_id
14+
network_area_id = var.network_area_id
15+
destination = { type = "cidrv4", value = "172.16.0.0/12" }
16+
next_hop = { type = "ipv4", value = stackit_network_interface.lan.ipv4 }
17+
}
18+
19+
resource "stackit_network_area_route" "rfc1918_192" {
20+
organization_id = var.organization_id
21+
network_area_id = var.network_area_id
22+
destination = { type = "cidrv4", value = "192.168.0.0/16" }
23+
next_hop = { type = "ipv4", value = stackit_network_interface.lan.ipv4 }
24+
}

modules/connectivity-regional/outputs.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
output "pfsense_public_ip" {
1+
output "firewall_public_ip" {
22
description = "The public IP address of the pfSense firewall WAN interface."
3-
value = stackit_public_ip.wan.ip
3+
value = stackit_public_ip.wan-ip.ip
44
}
55

6-
output "pfsense_wan_ip" {
7-
description = "The internal network area IP of the pfSense WAN interface (used as next hop in routes)."
6+
output "firewall_next_hop_ip" {
7+
description = "The IP address to be used as next hop for the default route in the landing zones (pfSense WAN IP)."
88
value = stackit_network_interface.wan.ipv4
99
}
1010

0 commit comments

Comments
 (0)