forked from cmdlabs/cmd-tf-aws-vpc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vpc-endpoints.tf
51 lines (47 loc) · 1.75 KB
/
vpc-endpoints.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
resource "aws_security_group" "sgforendpoint" {
count = length(var.vpc_endpoints) != 0 ? 1 : 0
name = "EndpointSG"
description = "Allow indbound and outbound traffic for VPC endpoint"
vpc_id = aws_vpc.main.id
}
resource "aws_security_group_rule" "allow_all_ingress" {
count = length(var.vpc_endpoints) != 0 ? 1 : 0
type = "ingress"
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
security_group_id = aws_security_group.sgforendpoint[0].id
}
resource "aws_security_group_rule" "allow_all_egress" {
count = length(var.vpc_endpoints) != 0 ? 1 : 0
type = "egress"
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
security_group_id = aws_security_group.sgforendpoint[0].id
}
resource "aws_vpc_endpoint" "vpc_endpoint" {
for_each = toset(var.vpc_endpoints)
vpc_id = aws_vpc.main.id
service_name = "com.amazonaws.${data.aws_region.current.name}.${each.value}"
vpc_endpoint_type = "Interface"
private_dns_enabled = "true"
security_group_ids = [aws_security_group.sgforendpoint[0].id]
subnet_ids = aws_subnet.private.*.id
tags = merge(
{ Name = "${var.vpc_name}-${each.value}-endpoint" },
var.tags
)
}
resource "aws_vpc_endpoint" "vpc_gatewayendpoint" {
for_each = toset(var.vpc_gatewayendpoints)
vpc_id = aws_vpc.main.id
service_name = "com.amazonaws.${data.aws_region.current.name}.${each.value}"
route_table_ids = concat("${aws_route_table.private.*.id}", "${aws_route_table.secure.*.id}")
tags = merge(
{ Name = "${var.vpc_name}-${each.value}-endpoint" },
var.tags
)
}