-
Notifications
You must be signed in to change notification settings - Fork 1
/
route_table.tf
68 lines (56 loc) · 1.49 KB
/
route_table.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# Create a route table
resource "aws_route_table" "rtable_public" {
vpc_id = aws_vpc.main.id
route {
cidr_block = "10.0.0.0/16"
gateway_id = "local"
}
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.gw.id
}
tags = {
Name = "main"
}
}
# Create a route table for private subnets
resource "aws_route_table" "private_rtable_a" {
vpc_id = aws_vpc.main.id
route {
cidr_block = "10.0.0.0/16"
gateway_id = "local"
}
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_nat_gateway.nat_gw_a.id
}
}
resource "aws_route_table" "private_rtable_b" {
vpc_id = aws_vpc.main.id
route {
cidr_block = "10.0.0.0/16"
gateway_id = "local"
}
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_nat_gateway.nat_gw_b.id
}
}
# Associate the route table with subnet
resource "aws_route_table_association" "rt_subnet_a" {
subnet_id = aws_subnet.public_a.id
route_table_id = aws_route_table.rtable_public.id
}
resource "aws_route_table_association" "rt_subnet_b" {
subnet_id = aws_subnet.public_b.id
route_table_id = aws_route_table.rtable_public.id
}
# Associate the route table with private subnets
resource "aws_route_table_association" "private_rt_subnet_a" {
subnet_id = aws_subnet.private_a.id
route_table_id = aws_route_table.private_rtable_a.id
}
resource "aws_route_table_association" "private_rt_subnet_b" {
subnet_id = aws_subnet.private_b.id
route_table_id = aws_route_table.private_rtable_b.id
}