From b408caef2acaf64b4153fb516648bc505d7a4e22 Mon Sep 17 00:00:00 2001 From: "Sven (AAMOS AI)" Date: Tue, 11 Aug 2026 21:31:46 +0700 Subject: [PATCH] infra: add vpc, subnets, routing and security groups --- infrastructure/terraform/network.tf | 152 ++++++++++++++++++++++++++++ 1 file changed, 152 insertions(+) create mode 100644 infrastructure/terraform/network.tf diff --git a/infrastructure/terraform/network.tf b/infrastructure/terraform/network.tf new file mode 100644 index 0000000..9d717dc --- /dev/null +++ b/infrastructure/terraform/network.tf @@ -0,0 +1,152 @@ +locals { + my_ip = "2.249.69.45" +} + +data "aws_availability_zones" "available" { + state = "available" +} + +resource "aws_vpc" "main" { + cidr_block = "10.0.0.0/16" + enable_dns_support = true + enable_dns_hostnames = true + tags = { + Name = "cibello-prod-vpc" + } +} + +resource "aws_internet_gateway" "main" { + vpc_id = aws_vpc.main.id + tags = { + Name = "cibello-prod-igw" + } +} + +resource "aws_subnet" "public" { + vpc_id = aws_vpc.main.id + cidr_block = "10.0.1.0/24" + availability_zone = data.aws_availability_zones.available.names[0] + map_public_ip_on_launch = true + tags = { + Name = "cibello-prod-public" + } +} + +resource "aws_subnet" "private_1" { + vpc_id = aws_vpc.main.id + cidr_block = "10.0.10.0/24" + availability_zone = data.aws_availability_zones.available.names[0] + tags = { + Name = "cibello-prod-private-1" + } +} + +resource "aws_subnet" "private_2" { + vpc_id = aws_vpc.main.id + cidr_block = "10.0.11.0/24" + availability_zone = data.aws_availability_zones.available.names[1] + tags = { + Name = "cibello-prod-private-2" + } +} + +resource "aws_route_table" "public" { + vpc_id = aws_vpc.main.id + route { + cidr_block = "0.0.0.0/0" + gateway_id = aws_internet_gateway.main.id + } + tags = { + Name = "cibello-prod-public-rt" + } +} + +resource "aws_route_table_association" "public" { + subnet_id = aws_subnet.public.id + route_table_id = aws_route_table.public.id +} + +resource "aws_route_table" "private" { + vpc_id = aws_vpc.main.id + tags = { + Name = "cibello-prod-private-rt" + } +} + +resource "aws_route_table_association" "private_1" { + subnet_id = aws_subnet.private_1.id + route_table_id = aws_route_table.private.id +} + +resource "aws_route_table_association" "private_2" { + subnet_id = aws_subnet.private_2.id + route_table_id = aws_route_table.private.id +} + +resource "aws_security_group" "web" { + name = "cibello-prod-sg-web" + description = "Web tier SG" + vpc_id = aws_vpc.main.id + + ingress { + description = "HTTP" + from_port = 80 + to_port = 80 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } + + ingress { + description = "HTTPS" + from_port = 443 + to_port = 443 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } + + ingress { + description = "SSH from operator" + from_port = 22 + to_port = 22 + protocol = "tcp" + cidr_blocks = ["${local.my_ip}/32"] + } + + egress { + description = "All outbound" + from_port = 0 + to_port = 0 + protocol = "-1" + cidr_blocks = ["0.0.0.0/0"] + } + + tags = { + Name = "cibello-prod-sg-web" + } +} + +resource "aws_security_group" "db" { + name = "cibello-prod-sg-db" + description = "Database tier SG" + vpc_id = aws_vpc.main.id + + ingress { + description = "PostgreSQL from web SG" + from_port = 5432 + to_port = 5432 + protocol = "tcp" + security_groups = [aws_security_group.web.id] + } + + egress { + description = "All outbound" + from_port = 0 + to_port = 0 + protocol = "-1" + cidr_blocks = ["0.0.0.0/0"] + } + + tags = { + Name = "cibello-prod-sg-db" + } +}