-
Notifications
You must be signed in to change notification settings - Fork 10
/
vpc_route_tables.tf
108 lines (85 loc) · 3.75 KB
/
vpc_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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# route tables
resource "aws_route_table" "rt_public" {
vpc_id = aws_vpc.main.id
tags = local.rt_public_tags
}
resource "aws_route_table" "rt_private" {
vpc_id = aws_vpc.main.id
tags = local.rt_private_tags
}
# route table associations
resource "aws_route_table_association" "rt_public_a" {
count = (local.enable_dynamic_subnets == true ? local.sn_public_a : 1)
subnet_id = aws_subnet.sn_public_a[count.index].id
route_table_id = aws_route_table.rt_public.id
}
resource "aws_route_table_association" "rt_public_b" {
count = (local.enable_dynamic_subnets == true ? local.sn_public_b : 1)
subnet_id = aws_subnet.sn_public_b[count.index].id
route_table_id = aws_route_table.rt_public.id
}
resource "aws_route_table_association" "rt_public_c" {
count = (local.enable_dynamic_subnets == true ? local.sn_public_c : 1)
subnet_id = aws_subnet.sn_public_c[count.index].id
route_table_id = aws_route_table.rt_public.id
}
resource "aws_route_table_association" "rt_private_a" {
count = local.multiaz_a_required ? 0 : (local.enable_dynamic_subnets == true ? local.sn_private_a : 1)
subnet_id = aws_subnet.sn_private_a[count.index].id
route_table_id = aws_route_table.rt_private.id
}
resource "aws_route_table_association" "rt_private_b" {
count = local.multiaz_b_required ? 0 : (local.enable_dynamic_subnets == true ? local.sn_private_b : 1)
subnet_id = aws_subnet.sn_private_b[count.index].id
route_table_id = aws_route_table.rt_private.id
}
resource "aws_route_table_association" "rt_private_c" {
count = local.multiaz_c_required ? 0 : (local.enable_dynamic_subnets == true ? local.sn_private_c : 1)
subnet_id = aws_subnet.sn_private_c[count.index].id
route_table_id = aws_route_table.rt_private.id
}
## VPC Endpoint
resource "aws_vpc_endpoint_route_table_association" "s3_public_rt" {
count = local.create_vpcep_s3
vpc_endpoint_id = aws_vpc_endpoint.s3[0].id
route_table_id = element(aws_route_table.rt_public.*.id, count.index)
}
resource "aws_vpc_endpoint_route_table_association" "s3_private_rt" {
count = local.create_vpcep_s3
vpc_endpoint_id = aws_vpc_endpoint.s3[0].id
route_table_id = element(aws_route_table.rt_private.*.id, count.index)
}
resource "aws_vpc_endpoint_route_table_association" "dynamodb_public_rt" {
count = local.create_vpcep_dynamodb
vpc_endpoint_id = aws_vpc_endpoint.dynamodb[0].id
route_table_id = element(aws_route_table.rt_public.*.id, count.index)
}
resource "aws_vpc_endpoint_route_table_association" "dynamodb_private_rt" {
count = local.create_vpcep_dynamodb
vpc_endpoint_id = aws_vpc_endpoint.dynamodb[0].id
route_table_id = element(aws_route_table.rt_private.*.id, count.index)
}
# routes
resource "aws_route" "rt_public_default" {
count = local.create_igw
route_table_id = aws_route_table.rt_public.id
destination_cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.igw[count.index].id
depends_on = [aws_internet_gateway.igw]
}
resource "aws_route" "rt_private_default" {
count = local.create_nat
route_table_id = aws_route_table.rt_private.id
destination_cidr_block = "0.0.0.0/0"
nat_gateway_id = aws_nat_gateway.natgw.0.id
}
# transit gateway
resource "aws_route" "rt_private_transit_gateway" {
count = local.create_private_tgw_routes
route_table_id = aws_route_table.rt_private.id
destination_cidr_block = element(var.tgw_destination_cidr_blocks, count.index)
transit_gateway_id = aws_ec2_transit_gateway_vpc_attachment.network_transit_gateway[0].transit_gateway_id
depends_on = [
aws_ec2_transit_gateway_vpc_attachment.network_transit_gateway,
]
}