01: infra
This commit is contained in:
1 parent
ec9bb74be0
commit
341cd05ac5
71 files changed
+2058
-1
No files matched your search
@@ -0,0 +1,120 @@
|
||||
# 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
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
# Network module variables
|
||||
linode_region = "us-east"
|
||||
environment = "staging"
|
||||
@@ -0,0 +1,25 @@
|
||||
# Variables for Networking module
|
||||
|
||||
variable "linode_region" {
|
||||
description = "Linode region for networking resources"
|
||||
type = string
|
||||
default = "us-east"
|
||||
}
|
||||
|
||||
variable "tags" {
|
||||
description = "Common tags for all resources"
|
||||
type = map(string)
|
||||
default = {
|
||||
ManagedBy = "terraform"
|
||||
Project = "hapi"
|
||||
}
|
||||
}
|
||||
|
||||
variable "environment" {
|
||||
description = "Deployment environment (staging or production)"
|
||||
type = string
|
||||
validation {
|
||||
condition = contains(["staging", "production"], var.environment)
|
||||
error_message = "Environment must be 'staging' or 'production'."
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user