121 lines
2.6 KiB
Terraform
121 lines
2.6 KiB
Terraform
# Networking module for HAPI
|
|
# Creates firewall rules for API, PostgreSQL, and Adminer
|
|
|
|
resource "linode_firewall" "hapi" {
|
|
label = "hapi-firewall"
|
|
tags = var.tags
|
|
|
|
# Inbound rules
|
|
inbound = [
|
|
{
|
|
label = "allow-api"
|
|
protocol = "tcp"
|
|
ports = "8000"
|
|
cidrs = ["0.0.0.0/0", "::/0"]
|
|
},
|
|
{
|
|
label = "allow-postgres"
|
|
protocol = "tcp"
|
|
ports = "5432"
|
|
cidrs = ["10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16"]
|
|
},
|
|
{
|
|
label = "allow-adminer"
|
|
protocol = "tcp"
|
|
ports = "8080"
|
|
cidrs = ["0.0.0.0/0", "::/0"]
|
|
},
|
|
{
|
|
label = "allow-https"
|
|
protocol = "tcp"
|
|
ports = "443"
|
|
cidrs = ["0.0.0.0/0", "::/0"]
|
|
},
|
|
{
|
|
label = "allow-http"
|
|
protocol = "tcp"
|
|
ports = "80"
|
|
cidrs = ["0.0.0.0/0", "::/0"]
|
|
}
|
|
]
|
|
|
|
# Outbound rules
|
|
outbound = [
|
|
{
|
|
label = "allow-all-outbound"
|
|
protocol = "tcp"
|
|
ports = "0-65535"
|
|
cidrs = ["0.0.0.0/0", "::/0"]
|
|
}
|
|
]
|
|
}
|
|
|
|
resource "linode_firewall_rule" "api_health" {
|
|
for_each = toset(["staging", "production"])
|
|
|
|
firewall_id = linode_firewall.hapi.id
|
|
label = "api-health-${each.key}"
|
|
direction = "inbound"
|
|
protocol = "tcp"
|
|
ports = "8000"
|
|
cidrs = ["0.0.0.0/0", "::/0"]
|
|
}
|
|
|
|
resource "linode_firewall_rule" "adminer_access" {
|
|
for_each = toset(["staging", "production"])
|
|
|
|
firewall_id = linode_firewall.hapi.id
|
|
label = "adminer-${each.key}"
|
|
direction = "inbound"
|
|
protocol = "tcp"
|
|
ports = "8080"
|
|
cidrs = ["0.0.0.0/0", "::/0"]
|
|
}
|
|
|
|
# Firewall rule configurations
|
|
locals {
|
|
firewall_config = {
|
|
staging = {
|
|
api_port = 8000
|
|
postgres_port = 5432
|
|
adminer_port = 8080
|
|
}
|
|
production = {
|
|
api_port = 8000
|
|
postgres_port = 5432
|
|
adminer_port = 8080
|
|
}
|
|
}
|
|
}
|
|
|
|
output "firewall_rules" {
|
|
description = "Firewall rules configuration"
|
|
value = {
|
|
api = {
|
|
port = 8000
|
|
protocol = "tcp"
|
|
cidrs = ["0.0.0.0/0", "::/0"]
|
|
}
|
|
postgres = {
|
|
port = 5432
|
|
protocol = "tcp"
|
|
cidrs = ["10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16"]
|
|
}
|
|
adminer = {
|
|
port = 8080
|
|
protocol = "tcp"
|
|
cidrs = ["0.0.0.0/0", "::/0"]
|
|
}
|
|
}
|
|
}
|
|
|
|
output "firewall_id" {
|
|
description = "ID of the main firewall"
|
|
value = linode_firewall.hapi.id
|
|
}
|
|
|
|
output "firewall_label" {
|
|
description = "Label of the main firewall"
|
|
value = linode_firewall.hapi.label
|
|
}
|