Files
hapi/infra/network/main.tf
T
Bobby 494f38c1f3 01a: update Linode Terraform for provider v2
- Update all modules to use Linode provider v2 (linode/linode ~> 2.0)
- Replace deprecated cluster attribute with region in all modules
- Update firewall to use ipv4/ipv6 instead of cidrs (TCP/UDP protocols)
- Update LKE endpoint output to use api_endpoints[0] instead of deprecated hostname
- Add OBJECT_STORAGE_CLUSTER variable for object storage configuration
- Update Makefile with new variables and validate target
- Add storage/outputs.tf for standardized object storage outputs
- Update .env and .env.example with clean format (no inline comments)
- Update all terraform.tfvars.example files for consistency
2026-11-17 22:09:31 -05:00

129 lines
2.6 KiB
Terraform

# Networking module for HAPI
# Creates firewall rules for API, PostgreSQL, and Adminer
terraform {
required_providers {
linode = {
source = "linode/linode"
version = "~> 2.0"
}
random = {
source = "hashicorp/random"
version = "~> 3.0"
}
}
}
resource "linode_firewall" "hapi" {
label = "hapi-firewall-${var.environment}"
tags = toset([for k, v in var.tags : "${k}=${v}"])
# Inbound policy
inbound_policy = "DROP"
# Outbound policy
outbound_policy = "DROP"
# Inbound rules
inbound {
action = "ACCEPT"
label = "allow-api-${var.environment}"
protocol = "TCP"
ports = "8000"
ipv4 = ["0.0.0.0/0"]
ipv6 = ["::/0"]
}
inbound {
action = "ACCEPT"
label = "allow-postgres-${var.environment}"
protocol = "TCP"
ports = "5432"
ipv4 = ["10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16"]
}
inbound {
action = "ACCEPT"
label = "allow-adminer-${var.environment}"
protocol = "TCP"
ports = "8080"
ipv4 = ["0.0.0.0/0"]
ipv6 = ["::/0"]
}
inbound {
action = "ACCEPT"
label = "allow-https-${var.environment}"
protocol = "TCP"
ports = "443"
ipv4 = ["0.0.0.0/0"]
ipv6 = ["::/0"]
}
inbound {
action = "ACCEPT"
label = "allow-http-${var.environment}"
protocol = "TCP"
ports = "80"
ipv4 = ["0.0.0.0/0"]
ipv6 = ["::/0"]
}
# Outbound rules
outbound {
action = "ACCEPT"
label = "allow-all-outbound-${var.environment}"
protocol = "TCP"
ports = "0-65535"
ipv4 = ["0.0.0.0/0"]
ipv6 = ["::/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
}