Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions eks-install/modules/vpc/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,19 @@ resource "aws_internet_gateway" "main" {
}

resource "aws_eip" "nat" {
count = length(var.public_subnet_cidrs)
domain = "vpc"

tags = {
Name = "${var.cluster_name}-nat-${count.index + 1}"
Name = "${var.cluster_name}-nat"
}
}

resource "aws_nat_gateway" "main" {
count = length(var.public_subnet_cidrs)
allocation_id = aws_eip.nat[count.index].id
subnet_id = aws_subnet.public[count.index].id
allocation_id = aws_eip.nat.id
subnet_id = aws_subnet.public[0].id # Attach to the first public subnet

tags = {
Name = "${var.cluster_name}-nat-${count.index + 1}"
Name = "${var.cluster_name}-nat"
}
}

Expand All @@ -83,7 +81,7 @@ resource "aws_route_table" "private" {

route {
cidr_block = "0.0.0.0/0"
nat_gateway_id = aws_nat_gateway.main[count.index].id
nat_gateway_id = aws_nat_gateway.main.id # Single NAT Gateway for all private subnets
}

tags = {
Expand All @@ -94,11 +92,12 @@ resource "aws_route_table" "private" {
resource "aws_route_table_association" "private" {
count = length(var.private_subnet_cidrs)
subnet_id = aws_subnet.private[count.index].id
route_table_id = aws_route_table.private[count.index].id
route_table_id = aws_route_table.private.id # Associate all private subnets to this single route table
}
}

resource "aws_route_table_association" "public" {
count = length(var.public_subnet_cidrs)
subnet_id = aws_subnet.public[count.index].id
route_table_id = aws_route_table.public.id
}
}