-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathroute.tf
43 lines (37 loc) · 1.4 KB
/
route.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# Route tables for the subnets
resource "aws_route_table" "public_route_table" {
vpc_id = aws_vpc.this.id
tags = {
Name = "${var.project}-public-rtb"
}
}
resource "aws_route_table" "private_route_table" {
vpc_id = aws_vpc.this.id
tags = {
Name = "${var.project}-private-rtb"
}
}
resource "aws_route_table_association" "public_route_association" {
count = length(var.public_cidrs)
route_table_id = aws_route_table.public_route_table.id
subnet_id = aws_subnet.public_subnet[count.index].id
}
resource "aws_route_table_association" "private_route_association" {
count = length(var.private_cidrs)
route_table_id = aws_route_table.private_route_table.id
subnet_id = aws_subnet.private_subnet[count.index].id
}
resource "aws_route" "nat_gw_route" {
count = length(aws_nat_gateway.nat_gateway)
route_table_id = aws_route_table.private_route_table.id
nat_gateway_id = aws_nat_gateway.nat_gateway[count.index].id
destination_cidr_block = "0.0.0.0/0"
depends_on = [aws_nat_gateway.nat_gateway]
}
# Route the public subnet traffic through the Internet Gateway
resource "aws_route" "public_internet_igw_route" {
route_table_id = aws_route_table.public_route_table.id
gateway_id = aws_internet_gateway.this.id
destination_cidr_block = "0.0.0.0/0"
depends_on = [aws_internet_gateway.this]
}