-
Notifications
You must be signed in to change notification settings - Fork 18
/
subnet-public.tf
71 lines (62 loc) · 2.5 KB
/
subnet-public.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
resource "aws_subnet" "public" {
count = length(data.aws_availability_zones.available.names) > var.max_az ? var.max_az : length(data.aws_availability_zones.available.names)
vpc_id = aws_vpc.default.id
cidr_block = cidrsubnet(
aws_vpc.default.cidr_block,
var.newbits,
count.index + var.public_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_public, var.name, upper(data.aws_availability_zone.az[count.index].name_suffix), local.name_suffix)
"Scheme" = "public"
"EnvName" = var.name
"aws-cdk:subnet-name" = "Public"
"aws-cdk:subnet-type" = "Public"
},
local.kubernetes_clusters,
length(var.kubernetes_clusters) != 0 ? { "kubernetes.io/role/elb" = 1 } : {}
)
}
resource "aws_route_table" "public" {
vpc_id = aws_vpc.default.id
tags = merge(
var.tags,
{
"Name" = format(local.names[var.name_pattern].routetable_public, var.name, local.name_suffix)
"Scheme" = "public"
"EnvName" = var.name
},
)
}
resource "aws_route" "public_internet_route" {
route_table_id = aws_route_table.public.id
destination_cidr_block = "0.0.0.0/0"
gateway_id = var.network_firewall ? null : (var.attachInternetGateway ? aws_internet_gateway.default.id : null)
vpc_endpoint_id = var.network_firewall ? (aws_networkfirewall_firewall.default[0].firewall_status[0].sync_states[*].attachment[0].endpoint_id)[0] : null
lifecycle {
create_before_destroy = true
}
}
resource "aws_route_table_association" "public" {
count = length(data.aws_availability_zones.available.names) > var.max_az ? var.max_az : length(data.aws_availability_zones.available.names)
subnet_id = aws_subnet.public[count.index].id
route_table_id = aws_route_table.public.id
lifecycle {
# ignore_changes = ["subnet_id", "route_table_id"]
create_before_destroy = true
}
}
resource "aws_vpc_endpoint_route_table_association" "public" {
count = var.vpc_endpoint_s3_gateway ? 1 : 0
route_table_id = aws_route_table.public.id
vpc_endpoint_id = aws_vpc_endpoint.s3[0].id
}
resource "aws_vpc_endpoint_route_table_association" "dynamodb_public" {
count = var.vpc_endpoint_dynamodb_gateway ? 1 : 0
route_table_id = aws_route_table.public.id
vpc_endpoint_id = aws_vpc_endpoint.dynamodb[0].id
}