-
Notifications
You must be signed in to change notification settings - Fork 18
/
subnet-transit.tf
70 lines (61 loc) · 2.38 KB
/
subnet-transit.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
resource "aws_subnet" "transit" {
count = var.transit_subnet ? length(data.aws_availability_zones.available.names) > var.max_az ? var.max_az : length(data.aws_availability_zones.available.names) : 0
vpc_id = aws_vpc.default.id
cidr_block = cidrsubnet(
aws_vpc.default.cidr_block,
var.newbits,
count.index + var.transit_netnum_offset,
)
availability_zone = data.aws_availability_zones.available.names[count.index]
map_public_ip_on_launch = true
tags = merge(
var.tags,
{
"Name" = format(local.names[var.name_pattern].subnet_transit, var.name, upper(data.aws_availability_zone.az[count.index].name_suffix), local.name_suffix)
"Scheme" = "transit"
"EnvName" = var.name
"aws-cdk:subnet-name" = "Transit"
"aws-cdk:subnet-type" = "Public"
},
)
}
resource "aws_route_table" "transit" {
count = var.transit_subnet ? 1 : 0
vpc_id = aws_vpc.default.id
tags = merge(
var.tags,
{
"Name" = format(local.names[var.name_pattern].routetable_transit, var.name, local.name_suffix)
"Scheme" = "transit"
"EnvName" = var.name
},
)
}
resource "aws_route" "transit_internet_route" {
count = var.transit_subnet ? 1 : 0
route_table_id = aws_route_table.transit[0].id
destination_cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.default.id
lifecycle {
create_before_destroy = true
}
}
resource "aws_route_table_association" "transit" {
count = var.transit_subnet ? length(data.aws_availability_zones.available.names) > var.max_az ? var.max_az : length(data.aws_availability_zones.available.names) : 0
subnet_id = aws_subnet.transit[count.index].id
route_table_id = aws_route_table.transit[0].id
lifecycle {
# ignore_changes = ["subnet_id", "route_table_id"]
create_before_destroy = true
}
}
resource "aws_vpc_endpoint_route_table_association" "transit" {
count = var.transit_subnet && var.vpc_endpoint_s3_gateway ? 1 : 0
route_table_id = aws_route_table.transit[0].id
vpc_endpoint_id = aws_vpc_endpoint.s3[0].id
}
resource "aws_vpc_endpoint_route_table_association" "dynamodb_transit" {
count = var.transit_subnet && var.vpc_endpoint_dynamodb_gateway ? 1 : 0
route_table_id = aws_route_table.transit[0].id
vpc_endpoint_id = aws_vpc_endpoint.dynamodb[0].id
}