# ============================================================================= # ROUTING # # El path completo de un flujo de egress: # app -> GWLBE (misma AZ) -> GWLB -> firewall -> GWLB -> GWLBE -> NAT GW -> IGW # # El path de un flujo hibrido entrante: # home lab -> VGW -> [edge route table] -> GWLBE -> firewall -> GWLBE -> app # ============================================================================= # --- Public: NAT GW + IGW ---------------------------------------------------- # El retorno del NAT GW tiene que volver por el firewall, si no el flujo queda # asimetrico y solo se inspecciona la ida. resource "aws_route_table" "public" { for_each = local.subnets vpc_id = aws_vpc.lab.id tags = { Name = "kf-rt-public-${each.key}" } } resource "aws_route" "public_default" { for_each = aws_route_table.public route_table_id = each.value.id destination_cidr_block = "0.0.0.0/0" gateway_id = aws_internet_gateway.igw.id } resource "aws_route" "public_return_to_fw" { for_each = local.subnets route_table_id = aws_route_table.public[each.key].id destination_cidr_block = each.value.app vpc_endpoint_id = aws_vpc_endpoint.gwlbe[each.key].id } resource "aws_route_table_association" "public" { for_each = aws_subnet.public subnet_id = each.value.id route_table_id = aws_route_table.public[each.key].id } # --- Mgmt -------------------------------------------------------------------- # Trafico de gestion, no se inspecciona a proposito: si el firewall se cae, # igual se puede llegar a administrarlo. resource "aws_route_table" "mgmt" { vpc_id = aws_vpc.lab.id route { cidr_block = "0.0.0.0/0" gateway_id = aws_internet_gateway.igw.id } tags = { Name = "kf-rt-mgmt" } } resource "aws_route_table_association" "mgmt" { for_each = aws_subnet.mgmt subnet_id = each.value.id route_table_id = aws_route_table.mgmt.id } # --- Fwdata ------------------------------------------------------------------ # Solo la ruta local. El GENEVE nace y muere dentro de la VPC. resource "aws_route_table" "fwdata" { vpc_id = aws_vpc.lab.id tags = { Name = "kf-rt-fwdata" } } resource "aws_route_table_association" "fwdata" { for_each = aws_subnet.fwdata subnet_id = each.value.id route_table_id = aws_route_table.fwdata.id } # --- GWLBE: salida despues de inspeccion ------------------------------------- # Aca cae el trafico ya inspeccionado que devuelve el firewall. resource "aws_route_table" "gwlbe" { for_each = local.subnets vpc_id = aws_vpc.lab.id route { cidr_block = "0.0.0.0/0" nat_gateway_id = aws_nat_gateway.nat[each.key].id } tags = { Name = "kf-rt-gwlbe-${each.key}" } } resource "aws_route_table_association" "gwlbe" { for_each = aws_subnet.gwlbe subnet_id = each.value.id route_table_id = aws_route_table.gwlbe[each.key].id } # Los prefijos del lab llegan por BGP. GOTCHA #1 del post anterior sigue # vigente: la propagacion viene apagada por defecto. resource "aws_vpn_gateway_route_propagation" "gwlbe" { for_each = aws_route_table.gwlbe vpn_gateway_id = aws_vpn_gateway.vgw.id route_table_id = each.value.id } resource "aws_vpn_gateway_route_propagation" "mgmt" { vpn_gateway_id = aws_vpn_gateway.vgw.id route_table_id = aws_route_table.mgmt.id } # --- App: todo sale por el GWLBE --------------------------------------------- # Sin propagacion del VGW aca: si se propagaran los prefijos del lab, el # trafico iria directo al VGW sin pasar por el firewall. resource "aws_route_table" "app" { for_each = local.subnets vpc_id = aws_vpc.lab.id tags = { Name = "kf-rt-app-${each.key}" } } resource "aws_route" "app_default" { for_each = local.subnets route_table_id = aws_route_table.app[each.key].id destination_cidr_block = "0.0.0.0/0" vpc_endpoint_id = aws_vpc_endpoint.gwlbe[each.key].id } resource "aws_route" "app_to_lab" { for_each = local.app_lab_routes route_table_id = aws_route_table.app[each.value.az].id destination_cidr_block = each.value.cidr vpc_endpoint_id = aws_vpc_endpoint.gwlbe[each.value.az].id } resource "aws_route_table_association" "app" { for_each = aws_subnet.app subnet_id = each.value.id route_table_id = aws_route_table.app[each.key].id } # --- Edge route table del VGW ------------------------------------------------ # Esto es lo que hace que el trafico hibrido se inspeccione. Sin esta # asociacion el trafico del tunel entra directo a las subnets app. resource "aws_route_table" "vgw_edge" { vpc_id = aws_vpc.lab.id tags = { Name = "kf-rt-vgw-edge" } } resource "aws_route" "vgw_edge_to_app" { for_each = local.subnets route_table_id = aws_route_table.vgw_edge.id destination_cidr_block = each.value.app vpc_endpoint_id = aws_vpc_endpoint.gwlbe[each.key].id } resource "aws_route_table_association" "vgw_edge" { gateway_id = aws_vpn_gateway.vgw.id route_table_id = aws_route_table.vgw_edge.id }