-
Notifications
You must be signed in to change notification settings - Fork 13
/
route_tables.tf
37 lines (30 loc) · 1.07 KB
/
route_tables.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
# Public Route Table
resource "aws_route_table" "public_rt" {
vpc_id = aws_vpc.main_vpc.id
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.internet_gateway.id
}
tags = merge(var.tags, { Name = "${var.name}-${var.environment}-public-rt" })
}
# Private Route Table
resource "aws_route_table" "private_rt" {
vpc_id = aws_vpc.main_vpc.id
route {
cidr_block = "0.0.0.0/0"
nat_gateway_id = aws_nat_gateway.nat_gateway.id
}
tags = merge(var.tags, { Name = "${var.name}-${var.environment}-private-rt" })
}
# Public Route Table Associations
resource "aws_route_table_association" "public_rt_association" {
count = length(aws_subnet.public_subnets)
subnet_id = aws_subnet.public_subnets[count.index].id
route_table_id = aws_route_table.public_rt.id
}
# Private Route Table Associations
resource "aws_route_table_association" "private_rt_association" {
count = length(aws_subnet.private_subnets)
subnet_id = aws_subnet.private_subnets[count.index].id
route_table_id = aws_route_table.private_rt.id
}