resource "aws_vpc" "lab" { cidr_block = var.vpc_cidr enable_dns_support = true enable_dns_hostnames = true tags = { Name = "kf-gwlb-vpc" } } resource "aws_internet_gateway" "igw" { vpc_id = aws_vpc.lab.id tags = { Name = "kf-gwlb-igw" } } # --- Subnets ----------------------------------------------------------------- resource "aws_subnet" "public" { for_each = local.subnets vpc_id = aws_vpc.lab.id cidr_block = each.value.public availability_zone = local.az[each.key] tags = { Name = "kf-public-${each.key}" } } resource "aws_subnet" "mgmt" { for_each = local.subnets vpc_id = aws_vpc.lab.id cidr_block = each.value.mgmt availability_zone = local.az[each.key] tags = { Name = "kf-mgmt-${each.key}" } } resource "aws_subnet" "fwdata" { for_each = local.subnets vpc_id = aws_vpc.lab.id cidr_block = each.value.fwdata availability_zone = local.az[each.key] tags = { Name = "kf-fwdata-${each.key}" } } resource "aws_subnet" "gwlbe" { for_each = local.subnets vpc_id = aws_vpc.lab.id cidr_block = each.value.gwlbe availability_zone = local.az[each.key] tags = { Name = "kf-gwlbe-${each.key}" } } resource "aws_subnet" "app" { for_each = local.subnets vpc_id = aws_vpc.lab.id cidr_block = each.value.app availability_zone = local.az[each.key] tags = { Name = "kf-app-${each.key}" } } # --- NAT Gateway por AZ ------------------------------------------------------ # Uno por AZ. Con uno solo compartido el retorno cruza AZ y el path se vuelve # dificil de explicar. Son US$0.045/hr cada uno: el segundo item mas caro # despues de los firewalls. resource "aws_eip" "nat" { for_each = local.subnets domain = "vpc" tags = { Name = "kf-eip-nat-${each.key}" } depends_on = [aws_internet_gateway.igw] } resource "aws_nat_gateway" "nat" { for_each = local.subnets allocation_id = aws_eip.nat[each.key].id subnet_id = aws_subnet.public[each.key].id tags = { Name = "kf-nat-${each.key}" } depends_on = [aws_internet_gateway.igw] } # --- Security groups --------------------------------------------------------- resource "aws_security_group" "mgmt" { name = "kf-sg-mgmt" description = "Gestion de los VM-Series" vpc_id = aws_vpc.lab.id ingress { description = "HTTPS GUI" from_port = 443 to_port = 443 protocol = "tcp" cidr_blocks = concat(var.admin_cidrs, var.lab_cidrs) } ingress { description = "SSH" from_port = 22 to_port = 22 protocol = "tcp" cidr_blocks = concat(var.admin_cidrs, var.lab_cidrs) } ingress { description = "ICMP" from_port = -1 to_port = -1 protocol = "icmp" cidr_blocks = concat(var.admin_cidrs, var.lab_cidrs) } egress { from_port = 0 to_port = 0 protocol = "-1" cidr_blocks = ["0.0.0.0/0"] } tags = { Name = "kf-sg-mgmt" } } # GOTCHA GWLB #1: si falta el 6081 el target queda unhealthy y AWS no dice # por que. Es el error mas comun de toda la integracion. resource "aws_security_group" "fwdata" { name = "kf-sg-fwdata" description = "Interfaz de datos: GENEVE + health check del GWLB" vpc_id = aws_vpc.lab.id ingress { description = "GENEVE desde el GWLB" from_port = 6081 to_port = 6081 protocol = "udp" cidr_blocks = [var.vpc_cidr] } ingress { description = "Health check del target group" from_port = 80 to_port = 80 protocol = "tcp" cidr_blocks = [var.vpc_cidr] } ingress { from_port = -1 to_port = -1 protocol = "icmp" cidr_blocks = [var.vpc_cidr] } egress { from_port = 0 to_port = 0 protocol = "-1" cidr_blocks = ["0.0.0.0/0"] } tags = { Name = "kf-sg-fwdata" } } resource "aws_security_group" "app" { name = "kf-sg-app" description = "Workloads" vpc_id = aws_vpc.lab.id ingress { from_port = 0 to_port = 0 protocol = "-1" cidr_blocks = concat([var.vpc_cidr], var.lab_cidrs) } egress { from_port = 0 to_port = 0 protocol = "-1" cidr_blocks = ["0.0.0.0/0"] } tags = { Name = "kf-sg-app" } }