Skip to content

Commit 5c6a231

Browse files
committed
chore: update based on PR feedback
1 parent bb60b18 commit 5c6a231

File tree

7 files changed

+156
-147
lines changed

7 files changed

+156
-147
lines changed

UPGRADE-3.0.md

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@ Previously, VPC endpoints were configured as standalone resources with their own
1313
1. Move the endpoint resource from the main module to the sub-module. The example state move below is valid for all endpoints you might have configured (reference [`complete-vpc`](https://github.com/terraform-aws-modules/terraform-aws-vpc/tree/master/examples/complete-vpc) example for reference), where `ssmmessages` should be updated for and state move performed for each endpoint configured:
1414

1515
```
16-
tf state mv 'module.vpc.aws_vpc_endpoint.ssm[0]' 'module.vpc_endpoints.aws_vpc_endpoint.this["ssm"]'
17-
tf state mv 'module.vpc.aws_vpc_endpoint.ssmmessages[0]' 'module.vpc_endpoints.aws_vpc_endpoint.this["ssmmessages"]'
18-
tf state mv 'module.vpc.aws_vpc_endpoint.ec2[0]' 'module.vpc_endpoints.aws_vpc_endpoint.this["ec2"]'
16+
terraform state mv 'module.vpc.aws_vpc_endpoint.ssm[0]' 'module.vpc_endpoints.aws_vpc_endpoint.this["ssm"]'
17+
terraform state mv 'module.vpc.aws_vpc_endpoint.ssmmessages[0]' 'module.vpc_endpoints.aws_vpc_endpoint.this["ssmmessages"]'
18+
terraform state mv 'module.vpc.aws_vpc_endpoint.ec2[0]' 'module.vpc_endpoints.aws_vpc_endpoint.this["ec2"]'
1919
...
2020
```
2121

2222
2. Remove the gateway endpoint route table association separate resources. The route table associations are now managed in the VPC endpoint resource itself via the map of maps provided to the VPC endpoint sub-module. Perform the necessary removals for each route table association and for S3 and/or DynamoDB depending on your configuration:
2323

2424
```
25-
tf state rm 'module.vpc.aws_vpc_endpoint_route_table_association.intra_dynamodb[0]'
26-
tf state rm 'module.vpc.aws_vpc_endpoint_route_table_association.private_dynamodb[0]'
27-
tf state rm 'module.vpc.aws_vpc_endpoint_route_table_association.public_dynamodb[0]'
25+
terraform state rm 'module.vpc.aws_vpc_endpoint_route_table_association.intra_dynamodb[0]'
26+
terraform state rm 'module.vpc.aws_vpc_endpoint_route_table_association.private_dynamodb[0]'
27+
terraform state rm 'module.vpc.aws_vpc_endpoint_route_table_association.public_dynamodb[0]'
2828
...
2929
```
3030

@@ -43,14 +43,10 @@ tf state rm 'module.vpc.aws_vpc_endpoint_route_table_association.public_dynamodb
4343

4444
See the [VPC endpoint sub-module](modules/vpc-endpoints) for the more information on the variables to utilize for VPC endpoints
4545

46-
- None
47-
4846
3. Removed outputs:
4947

5048
- `vpc_endpoint_*`
5149

5250
4. Renamed outputs:
5351

54-
VPC endpoint outputs are now provided via the VPC endpoint sub-module and can be accessed via lookups. See [`complete-vpc`](https://github.com/terraform-aws-modules/terraform-aws-vpc/tree/master/examples/complete-vpc) for further examples of how to access VPC endpoint attributes from outputs.
55-
56-
- None
52+
VPC endpoint outputs are now provided via the VPC endpoint sub-module and can be accessed via lookups. See [`complete-vpc`](https://github.com/terraform-aws-modules/terraform-aws-vpc/tree/master/examples/complete-vpc) for further examples of how to access VPC endpoint attributes from outputs

examples/complete-vpc/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Note that this example may create resources which can cost money (AWS Elastic IP
3636
|------|--------|---------|
3737
| <a name="module_vpc"></a> [vpc](#module\_vpc) | ../../ | |
3838
| <a name="module_vpc_endpoints"></a> [vpc\_endpoints](#module\_vpc\_endpoints) | ../../modules/vpc-endpoints | |
39+
| <a name="module_vpc_endpoints_nocreate"></a> [vpc\_endpoints\_nocreate](#module\_vpc\_endpoints\_nocreate) | ../../modules/vpc-endpoints | |
3940

4041
## Resources
4142

examples/complete-vpc/main.tf

Lines changed: 65 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -12,65 +12,6 @@ locals {
1212
}
1313
}
1414

15-
################################################################################
16-
# Supporting Resources
17-
################################################################################
18-
19-
data "aws_security_group" "default" {
20-
name = "default"
21-
vpc_id = module.vpc.vpc_id
22-
}
23-
24-
# Data source used to avoid race condition
25-
data "aws_vpc_endpoint_service" "dynamodb" {
26-
service = "dynamodb"
27-
28-
filter {
29-
name = "service-type"
30-
values = ["Gateway"]
31-
}
32-
}
33-
34-
data "aws_iam_policy_document" "dynamodb_endpoint_policy" {
35-
statement {
36-
effect = "Deny"
37-
actions = ["dynamodb:*"]
38-
resources = ["*"]
39-
40-
principals {
41-
type = "*"
42-
identifiers = ["*"]
43-
}
44-
45-
condition {
46-
test = "StringNotEquals"
47-
variable = "aws:sourceVpce"
48-
49-
values = [data.aws_vpc_endpoint_service.dynamodb.id]
50-
}
51-
}
52-
}
53-
54-
data "aws_iam_policy_document" "generic_endpoint_policy" {
55-
statement {
56-
effect = "Deny"
57-
actions = ["*"]
58-
resources = ["*"]
59-
60-
principals {
61-
type = "*"
62-
identifiers = ["*"]
63-
}
64-
65-
condition {
66-
test = "StringNotEquals"
67-
variable = "aws:sourceVpce"
68-
69-
values = [data.aws_vpc_endpoint_service.dynamodb.id]
70-
}
71-
}
72-
}
73-
7415
################################################################################
7516
# VPC Module
7617
################################################################################
@@ -225,3 +166,68 @@ module "vpc_endpoints" {
225166
Endpoint = "true"
226167
})
227168
}
169+
170+
module "vpc_endpoints_nocreate" {
171+
source = "../../modules/vpc-endpoints"
172+
173+
create = false
174+
}
175+
176+
################################################################################
177+
# Supporting Resources
178+
################################################################################
179+
180+
data "aws_security_group" "default" {
181+
name = "default"
182+
vpc_id = module.vpc.vpc_id
183+
}
184+
185+
# Data source used to avoid race condition
186+
data "aws_vpc_endpoint_service" "dynamodb" {
187+
service = "dynamodb"
188+
189+
filter {
190+
name = "service-type"
191+
values = ["Gateway"]
192+
}
193+
}
194+
195+
data "aws_iam_policy_document" "dynamodb_endpoint_policy" {
196+
statement {
197+
effect = "Deny"
198+
actions = ["dynamodb:*"]
199+
resources = ["*"]
200+
201+
principals {
202+
type = "*"
203+
identifiers = ["*"]
204+
}
205+
206+
condition {
207+
test = "StringNotEquals"
208+
variable = "aws:sourceVpce"
209+
210+
values = [data.aws_vpc_endpoint_service.dynamodb.id]
211+
}
212+
}
213+
}
214+
215+
data "aws_iam_policy_document" "generic_endpoint_policy" {
216+
statement {
217+
effect = "Deny"
218+
actions = ["*"]
219+
resources = ["*"]
220+
221+
principals {
222+
type = "*"
223+
identifiers = ["*"]
224+
}
225+
226+
condition {
227+
test = "StringNotEquals"
228+
variable = "aws:sourceVpce"
229+
230+
values = [data.aws_vpc_endpoint_service.dynamodb.id]
231+
}
232+
}
233+
}

examples/vpc-flow-logs/main.tf

Lines changed: 63 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,69 @@ locals {
99
cloudwatch_log_group_name = "vpc-flow-logs-to-cloudwatch-${random_pet.this.id}"
1010
}
1111

12+
################################################################################
13+
# VPC Module
14+
################################################################################
15+
16+
module "vpc_with_flow_logs_s3_bucket" {
17+
source = "../../"
18+
19+
name = "vpc-flow-logs-s3-bucket"
20+
cidr = "10.30.0.0/16"
21+
22+
azs = ["${local.region}a"]
23+
public_subnets = ["10.30.101.0/24"]
24+
25+
enable_flow_log = true
26+
flow_log_destination_type = "s3"
27+
flow_log_destination_arn = module.s3_bucket.this_s3_bucket_arn
28+
29+
vpc_flow_log_tags = {
30+
Name = "vpc-flow-logs-s3-bucket"
31+
}
32+
}
33+
34+
# CloudWatch Log Group and IAM role created automatically
35+
module "vpc_with_flow_logs_cloudwatch_logs_default" {
36+
source = "../../"
37+
38+
name = "vpc-flow-logs-cloudwatch-logs-default"
39+
cidr = "10.10.0.0/16"
40+
41+
azs = ["${local.region}a"]
42+
public_subnets = ["10.10.101.0/24"]
43+
44+
# Cloudwatch log group and IAM role will be created
45+
enable_flow_log = true
46+
create_flow_log_cloudwatch_log_group = true
47+
create_flow_log_cloudwatch_iam_role = true
48+
flow_log_max_aggregation_interval = 60
49+
50+
vpc_flow_log_tags = {
51+
Name = "vpc-flow-logs-cloudwatch-logs-default"
52+
}
53+
}
54+
55+
# CloudWatch Log Group and IAM role created separately
56+
module "vpc_with_flow_logs_cloudwatch_logs" {
57+
source = "../../"
58+
59+
name = "vpc-flow-logs-cloudwatch-logs"
60+
cidr = "10.20.0.0/16"
61+
62+
azs = ["${local.region}a"]
63+
public_subnets = ["10.20.101.0/24"]
64+
65+
enable_flow_log = true
66+
flow_log_destination_type = "cloud-watch-logs"
67+
flow_log_destination_arn = aws_cloudwatch_log_group.flow_log.arn
68+
flow_log_cloudwatch_iam_role_arn = aws_iam_role.vpc_flow_log_cloudwatch.arn
69+
70+
vpc_flow_log_tags = {
71+
Name = "vpc-flow-logs-cloudwatch-logs"
72+
}
73+
}
74+
1275
################################################################################
1376
# Supporting Resources
1477
################################################################################
@@ -105,66 +168,3 @@ data "aws_iam_policy_document" "vpc_flow_log_cloudwatch" {
105168
resources = ["*"]
106169
}
107170
}
108-
109-
################################################################################
110-
# VPC Module
111-
################################################################################
112-
113-
module "vpc_with_flow_logs_s3_bucket" {
114-
source = "../../"
115-
116-
name = "vpc-flow-logs-s3-bucket"
117-
cidr = "10.30.0.0/16"
118-
119-
azs = ["${local.region}a"]
120-
public_subnets = ["10.30.101.0/24"]
121-
122-
enable_flow_log = true
123-
flow_log_destination_type = "s3"
124-
flow_log_destination_arn = module.s3_bucket.this_s3_bucket_arn
125-
126-
vpc_flow_log_tags = {
127-
Name = "vpc-flow-logs-s3-bucket"
128-
}
129-
}
130-
131-
# CloudWatch Log Group and IAM role created automatically
132-
module "vpc_with_flow_logs_cloudwatch_logs_default" {
133-
source = "../../"
134-
135-
name = "vpc-flow-logs-cloudwatch-logs-default"
136-
cidr = "10.10.0.0/16"
137-
138-
azs = ["${local.region}a"]
139-
public_subnets = ["10.10.101.0/24"]
140-
141-
# Cloudwatch log group and IAM role will be created
142-
enable_flow_log = true
143-
create_flow_log_cloudwatch_log_group = true
144-
create_flow_log_cloudwatch_iam_role = true
145-
flow_log_max_aggregation_interval = 60
146-
147-
vpc_flow_log_tags = {
148-
Name = "vpc-flow-logs-cloudwatch-logs-default"
149-
}
150-
}
151-
152-
# CloudWatch Log Group and IAM role created separately
153-
module "vpc_with_flow_logs_cloudwatch_logs" {
154-
source = "../../"
155-
156-
name = "vpc-flow-logs-cloudwatch-logs"
157-
cidr = "10.20.0.0/16"
158-
159-
azs = ["${local.region}a"]
160-
public_subnets = ["10.20.101.0/24"]
161-
162-
enable_flow_log = true
163-
flow_log_destination_type = "cloud-watch-logs"
164-
flow_log_destination_arn = aws_cloudwatch_log_group.flow_log.arn
165-
flow_log_cloudwatch_iam_role_arn = aws_iam_role.vpc_flow_log_cloudwatch.arn
166-
167-
vpc_flow_log_tags = {
168-
Name = "vpc-flow-logs-cloudwatch-logs"
169-
}
170-
}

modules/vpc-endpoints/README.md

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,30 @@
22

33
Terraform sub-module which creates VPC endpoint resources on AWS.
44

5-
The following resources are supported:
6-
7-
- [aws_vpc_endpoint](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpc_endpoint)
8-
95
## Usage
106

117
See [`examples`](./examples) directory for working examples to reference:
128

139
```hcl
1410
module "endpoints" {
15-
source = "terraform-aws-modules/vpc/aws//vpc-endpoints"
11+
source = "terraform-aws-modules/vpc/aws//modules/vpc-endpoints"
1612
1713
vpc_id = "vpc-12345678"
1814
security_group_ids = ["sg-12345678"]
1915
20-
gateway_endpoints = {
16+
endpoints = {
2117
s3 = {
18+
# interface endpoint
2219
service = "s3"
2320
private_dns_enabled = true
24-
route_table_ids = ["rt-12322456", "rt-43433343", "rt-11223344"]
2521
tags = { Name = "s3-vpc-endpoint" }
2622
},
2723
dynamodb = {
24+
# gateway endpoint
2825
service = "dynamodb"
2926
route_table_ids = ["rt-12322456", "rt-43433343", "rt-11223344"]
3027
tags = { Name = "dynamodb-vpc-endpoint" }
31-
}
32-
}
33-
34-
interface_endpoints = {
28+
},
3529
sns = {
3630
service = "sns"
3731
subnet_ids = ["subnet-12345678", "subnet-87654321"]
@@ -86,12 +80,13 @@ No modules.
8680

8781
| Name | Description | Type | Default | Required |
8882
|------|-------------|------|---------|:--------:|
83+
| <a name="input_create"></a> [create](#input\_create) | Determines whether resources will be created | `bool` | `true` | no |
8984
| <a name="input_endpoints"></a> [endpoints](#input\_endpoints) | A map of interface and/or gateway endpoints containing their properties and configurations | `any` | `{}` | no |
9085
| <a name="input_security_group_ids"></a> [security\_group\_ids](#input\_security\_group\_ids) | Default security group IDs to associate with the VPC endpoints | `list(string)` | `[]` | no |
9186
| <a name="input_subnet_ids"></a> [subnet\_ids](#input\_subnet\_ids) | Default subnets IDs to associate with the VPC endpoints | `list(string)` | `[]` | no |
9287
| <a name="input_tags"></a> [tags](#input\_tags) | A map of tags to use on all resources | `map(string)` | `{}` | no |
9388
| <a name="input_timeouts"></a> [timeouts](#input\_timeouts) | Define maximum timeout for creating, updating, and deleting VPC endpoint resources | `map(string)` | `{}` | no |
94-
| <a name="input_vpc_id"></a> [vpc\_id](#input\_vpc\_id) | The ID of the VPC in which the endpoint will be used | `string` | n/a | yes |
89+
| <a name="input_vpc_id"></a> [vpc\_id](#input\_vpc\_id) | The ID of the VPC in which the endpoint will be used | `string` | `null` | no |
9590

9691
## Outputs
9792

0 commit comments

Comments
 (0)