forked from jparnaudeau/terraform-aws-vpc-endpoints
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vpce_gateways.tf
45 lines (40 loc) · 1.4 KB
/
vpce_gateways.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
#####################################################################
# VPC Endpoints - Type Gateway
#####################################################################
locals {
# iterate over vpc endpoint gateways nested to the list of route table id
route_table_ids = flatten([
for tuple in var.vpcendpoints_gateways : [
for rt in tuple.route_table_ids : {
vpc_endpoint_id = tuple.id
route_table_id = rt
}
]
])
}
data "aws_vpc_endpoint_service" "vpce_service_gtw" {
for_each = { for tuple in var.vpcendpoints_gateways : tuple.id => tuple }
service = each.key
service_type = "Gateway"
}
resource "aws_vpc_endpoint" "vpce_gtw" {
for_each = { for tuple in var.vpcendpoints_gateways : tuple.id => tuple }
vpc_id = lookup(each.value, "vpc_id")
service_name = data.aws_vpc_endpoint_service.vpce_service_gtw[each.key].service_name
tags = merge(
{
"Name" = format(var.naming_pattern, "vpce", format("%s-gateway-endpoint", each.key))
},
lookup(each.value, "tags", []),
)
}
resource "aws_vpc_endpoint_route_table_association" "rt_assoc" {
for_each = { for k in local.route_table_ids : format("%s-%s", k.route_table_id, k.vpc_endpoint_id) =>
{
vpce_id = k.vpc_endpoint_id
rt_id = k.route_table_id
}
}
vpc_endpoint_id = aws_vpc_endpoint.vpce_gtw[each.value["vpce_id"]].id
route_table_id = each.value["rt_id"]
}