-
Notifications
You must be signed in to change notification settings - Fork 0
/
route-tables.tf
62 lines (52 loc) · 2.21 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
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
# aws_vpc creates a default rtb. We can map the Internet Gateway so the vpc has internet.
resource "aws_default_route_table" "terraform-vpc-default-route-table" {
default_route_table_id = aws_vpc.terraform-vpc.default_route_table_id
route {
# associated subnet can reach everywhere
cidr_block = "0.0.0.0/0"
# RTB uses this IGW to reach internet
gateway_id = aws_internet_gateway.terraform-vpc-igw.id
}
route {
# ipv6
ipv6_cidr_block = "::/0"
# RTB uses this IGW to reach internet
gateway_id = aws_internet_gateway.terraform-vpc-igw.id
}
tags = {
Name = "terraform-vpc-default-rtb"
}
}
# Associate above RTB to VPC subnet. This use case uses one RTB for all subnets.
resource "aws_route_table_association" "vpc-rtb-public-ap-southeast-1-assoc" {
count = length(aws_subnet.terraform-vpc-subnet-public-ap-southeast-1.*.id)
subnet_id = element(aws_subnet.terraform-vpc-subnet-public-ap-southeast-1.*.id, count.index)
route_table_id = aws_default_route_table.terraform-vpc-default-route-table.id
depends_on = [aws_subnet.terraform-vpc-subnet-public-ap-southeast-1]
}
# Route table for private subnet
resource "aws_route_table" "terraform-vpc-rtb-private-ap-southeast-1a" {
vpc_id = aws_vpc.terraform-vpc.id
# NAT instead of IGW for private subnets
route {
# associated subnet can reach everywhere
cidr_block = "0.0.0.0/0"
nat_gateway_id = aws_nat_gateway.terraform-nat-public-ap-southeast-1a.id
}
# ipv6
route {
ipv6_cidr_block = "::/0"
# RTB uses this EGW to reach internet
egress_only_gateway_id = aws_egress_only_internet_gateway.terraform-vpc-egw.id
}
tags = {
Name = "terraform-vpc-rtb-private-ap-southeast-1a"
}
}
# Associate above RTB to VPC subnet. This use case uses one RTB for all subnets.
resource "aws_route_table_association" "vpc-rtb-private-ap-southeast-1-assoc" {
count = length(aws_subnet.terraform-vpc-subnet-private-ap-southeast-1.*.id)
subnet_id = element(aws_subnet.terraform-vpc-subnet-private-ap-southeast-1.*.id, count.index)
route_table_id = aws_default_route_table.terraform-vpc-default-route-table.id
depends_on = [aws_subnet.terraform-vpc-subnet-private-ap-southeast-1]
}