-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvpc_endpoints.tf
196 lines (162 loc) · 6.06 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
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#-------------------------------------------------------------------------------
# Create the VPC endpoints.
#-------------------------------------------------------------------------------
#
# VPC interface endpoints
#
# STS interface endpoint
resource "aws_vpc_endpoint" "sts" {
provider = aws.sharedservicesprovisionaccount
private_dns_enabled = true
security_group_ids = [
aws_security_group.sts_endpoint.id,
]
service_name = "com.amazonaws.${var.aws_region}.sts"
vpc_endpoint_type = "Interface"
vpc_id = aws_vpc.the_vpc.id
}
# Interface endpoints associated with the SSM agent
resource "aws_vpc_endpoint" "ec2" {
provider = aws.sharedservicesprovisionaccount
private_dns_enabled = true
security_group_ids = [
# The CloudWatch agent reads a few pieces of data from the EC2
# endpoint. You can see this by inspecting the AWS-provided
# CloudWatchAgentServerPolicyIAM policy.
aws_security_group.cloudwatch_agent_endpoint.id,
aws_security_group.ec2_endpoint.id,
aws_security_group.ssm_agent_endpoint.id,
]
service_name = "com.amazonaws.${var.aws_region}.ec2"
vpc_endpoint_type = "Interface"
vpc_id = aws_vpc.the_vpc.id
}
resource "aws_vpc_endpoint" "ec2messages" {
provider = aws.sharedservicesprovisionaccount
private_dns_enabled = true
security_group_ids = [
aws_security_group.ssm_agent_endpoint.id,
]
service_name = "com.amazonaws.${var.aws_region}.ec2messages"
vpc_endpoint_type = "Interface"
vpc_id = aws_vpc.the_vpc.id
}
resource "aws_vpc_endpoint" "kms" {
provider = aws.sharedservicesprovisionaccount
private_dns_enabled = true
security_group_ids = [
aws_security_group.ssm_agent_endpoint.id,
]
service_name = "com.amazonaws.${var.aws_region}.kms"
vpc_endpoint_type = "Interface"
vpc_id = aws_vpc.the_vpc.id
}
resource "aws_vpc_endpoint" "ssm" {
provider = aws.sharedservicesprovisionaccount
private_dns_enabled = true
security_group_ids = [
aws_security_group.ssm_agent_endpoint.id,
aws_security_group.ssm_endpoint.id,
]
service_name = "com.amazonaws.${var.aws_region}.ssm"
vpc_endpoint_type = "Interface"
vpc_id = aws_vpc.the_vpc.id
}
resource "aws_vpc_endpoint" "ssmmessages" {
provider = aws.sharedservicesprovisionaccount
private_dns_enabled = true
security_group_ids = [
aws_security_group.ssm_agent_endpoint.id,
aws_security_group.ssm_endpoint.id,
]
service_name = "com.amazonaws.${var.aws_region}.ssmmessages"
vpc_endpoint_type = "Interface"
vpc_id = aws_vpc.the_vpc.id
}
# Interface endpoints associated with the CloudWatch agent
resource "aws_vpc_endpoint" "logs" {
provider = aws.sharedservicesprovisionaccount
private_dns_enabled = true
security_group_ids = [
aws_security_group.cloudwatch_agent_endpoint.id,
]
service_name = "com.amazonaws.${var.aws_region}.logs"
vpc_endpoint_type = "Interface"
vpc_id = aws_vpc.the_vpc.id
}
resource "aws_vpc_endpoint" "monitoring" {
provider = aws.sharedservicesprovisionaccount
private_dns_enabled = true
security_group_ids = [
aws_security_group.cloudwatch_agent_endpoint.id,
]
service_name = "com.amazonaws.${var.aws_region}.monitoring"
vpc_endpoint_type = "Interface"
vpc_id = aws_vpc.the_vpc.id
}
# Associate the STS interface endpoint with the private subnets
resource "aws_vpc_endpoint_subnet_association" "sts" {
provider = aws.sharedservicesprovisionaccount
for_each = toset(var.private_subnet_cidr_blocks)
subnet_id = module.private.subnets[each.value].id
vpc_endpoint_id = aws_vpc_endpoint.sts.id
}
# Associate the SSM interface endpoints with the private subnets
#
# Note that SSM requires several other endpoints to function properly.
# See here for more details:
# https://docs.aws.amazon.com/systems-manager/latest/userguide/setup-create-vpc.html#sysman-setting-up-vpc-create
resource "aws_vpc_endpoint_subnet_association" "ec2" {
provider = aws.sharedservicesprovisionaccount
for_each = toset(var.private_subnet_cidr_blocks)
subnet_id = module.private.subnets[each.value].id
vpc_endpoint_id = aws_vpc_endpoint.ec2.id
}
resource "aws_vpc_endpoint_subnet_association" "ec2messages" {
provider = aws.sharedservicesprovisionaccount
for_each = toset(var.private_subnet_cidr_blocks)
subnet_id = module.private.subnets[each.value].id
vpc_endpoint_id = aws_vpc_endpoint.ec2messages.id
}
resource "aws_vpc_endpoint_subnet_association" "kms" {
provider = aws.sharedservicesprovisionaccount
for_each = toset(var.private_subnet_cidr_blocks)
subnet_id = module.private.subnets[each.value].id
vpc_endpoint_id = aws_vpc_endpoint.kms.id
}
resource "aws_vpc_endpoint_subnet_association" "ssm" {
provider = aws.sharedservicesprovisionaccount
for_each = toset(var.private_subnet_cidr_blocks)
subnet_id = module.private.subnets[each.value].id
vpc_endpoint_id = aws_vpc_endpoint.ssm.id
}
resource "aws_vpc_endpoint_subnet_association" "ssmmessages" {
provider = aws.sharedservicesprovisionaccount
for_each = toset(var.private_subnet_cidr_blocks)
subnet_id = module.private.subnets[each.value].id
vpc_endpoint_id = aws_vpc_endpoint.ssmmessages.id
}
# Associate the CloudWatch agent interface endpoints with the private
# subnets.
resource "aws_vpc_endpoint_subnet_association" "logs" {
provider = aws.sharedservicesprovisionaccount
for_each = toset(var.private_subnet_cidr_blocks)
subnet_id = module.private.subnets[each.value].id
vpc_endpoint_id = aws_vpc_endpoint.logs.id
}
resource "aws_vpc_endpoint_subnet_association" "monitoring" {
provider = aws.sharedservicesprovisionaccount
for_each = toset(var.private_subnet_cidr_blocks)
subnet_id = module.private.subnets[each.value].id
vpc_endpoint_id = aws_vpc_endpoint.monitoring.id
}
#
# VPC gateway endpoints
#
# S3 gateway endpoint
resource "aws_vpc_endpoint" "s3" {
provider = aws.sharedservicesprovisionaccount
service_name = "com.amazonaws.${var.aws_region}.s3"
vpc_endpoint_type = "Gateway"
vpc_id = aws_vpc.the_vpc.id
}