Skip to content

Commit 1976823

Browse files
committed
fix: Add explicit parameters for S3 interface endpoint
This makes the existing S3 endpoint parameters purely for the gateway type and adds new parameters for the S3 interface type. The existing parameters that don't make sense for a gateway endpoint are removed as well as the parameter for choosing the type. The missing outputs are also added for parity with existing endpoints. Based on the work in terraform-aws-modules#575. Fixes terraform-aws-modules#603
1 parent cb96e06 commit 1976823

File tree

4 files changed

+72
-27
lines changed

4 files changed

+72
-27
lines changed

README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,8 @@ No Modules.
534534
| enable\_qldb\_session\_endpoint | Should be true if you want to provision an QLDB Session endpoint to the VPC | `bool` | `false` | no |
535535
| enable\_rds\_endpoint | Should be true if you want to provision an RDS endpoint to the VPC | `bool` | `false` | no |
536536
| enable\_rekognition\_endpoint | Should be true if you want to provision a Rekognition endpoint to the VPC | `bool` | `false` | no |
537-
| enable\_s3\_endpoint | Should be true if you want to provision an S3 endpoint to the VPC | `bool` | `false` | no |
537+
| enable\_s3\_endpoint | Should be true if you want to provision an S3 gateway endpoint to the VPC | `bool` | `false` | no |
538+
| enable\_s3\_interface\_endpoint | Should be true if you want to provision an S3 interface endpoint to the VPC | `bool` | `false` | no |
538539
| enable\_sagemaker\_api\_endpoint | Should be true if you want to provision a SageMaker API endpoint to the VPC | `bool` | `false` | no |
539540
| enable\_sagemaker\_notebook\_endpoint | Should be true if you want to provision a Sagemaker Notebook endpoint to the VPC | `bool` | `false` | no |
540541
| enable\_sagemaker\_runtime\_endpoint | Should be true if you want to provision a SageMaker Runtime endpoint to the VPC | `bool` | `false` | no |
@@ -665,10 +666,10 @@ No Modules.
665666
| rekognition\_endpoint\_subnet\_ids | The ID of one or more subnets in which to create a network interface for Rekognition endpoint. Only a single subnet within an AZ is supported. If omitted, private subnets will be used. | `list(string)` | `[]` | no |
666667
| reuse\_nat\_ips | Should be true if you don't want EIPs to be created for your NAT Gateways and will instead pass them in via the 'external\_nat\_ip\_ids' variable | `bool` | `false` | no |
667668
| s3\_endpoint\_policy | A policy to attach to the endpoint that controls access to the service. Defaults to full access | `string` | `null` | no |
668-
| s3\_endpoint\_private\_dns\_enabled | Whether or not to associate a private hosted zone with the specified VPC for S3 interface endpoint | `bool` | `false` | no |
669-
| s3\_endpoint\_security\_group\_ids | The ID of one or more security groups to associate with the network interface for S3 interface endpoint | `list(string)` | `[]` | no |
670-
| s3\_endpoint\_subnet\_ids | The ID of one or more subnets in which to create a network interface for S3 interface endpoint. Only a single subnet within an AZ is supported. If omitted, private subnets will be used. | `list(string)` | `[]` | no |
671-
| s3\_endpoint\_type | S3 VPC endpoint type. Note - S3 Interface type support is only available on AWS provider 3.10 and later | `string` | `"Gateway"` | no |
669+
| s3\_interface\_endpoint\_policy | A policy to attach to the endpoint that controls access to the service. Defaults to full access | `string` | `null` | no |
670+
| s3\_interface\_endpoint\_private\_dns\_enabled | Whether or not to associate a private hosted zone with the specified VPC for S3 interface endpoint | `bool` | `false` | no |
671+
| s3\_interface\_endpoint\_security\_group\_ids | The ID of one or more security groups to associate with the network interface for S3 interface endpoint | `list(string)` | `[]` | no |
672+
| s3\_interface\_endpoint\_subnet\_ids | The ID of one or more subnets in which to create a network interface for S3 interface endpoint. Only a single subnet within an AZ is supported. If omitted, private subnets will be used. | `list(string)` | `[]` | no |
672673
| sagemaker\_api\_endpoint\_policy | A policy to attach to the endpoint that controls access to the service. Defaults to full access | `string` | `null` | no |
673674
| sagemaker\_api\_endpoint\_private\_dns\_enabled | Whether or not to associate a private hosted zone with the specified VPC for SageMaker API endpoint | `bool` | `false` | no |
674675
| sagemaker\_api\_endpoint\_security\_group\_ids | The ID of one or more security groups to associate with the network interface for SageMaker API endpoint | `list(string)` | `[]` | no |
@@ -981,6 +982,9 @@ No Modules.
981982
| vpc\_endpoint\_rekognition\_network\_interface\_ids | One or more network interfaces for the VPC Endpoint for Rekognition. |
982983
| vpc\_endpoint\_s3\_id | The ID of VPC endpoint for S3 |
983984
| vpc\_endpoint\_s3\_pl\_id | The prefix list for the S3 VPC endpoint. |
985+
| vpc\_endpoint\_s3\_interface\_dns\_entry | The DNS entries for the VPC Endpoint for S3 interface. |
986+
| vpc\_endpoint\_s3\_interface\_id | The ID of VPC endpoint for S3 interface |
987+
| vpc\_endpoint\_s3\_interface\_network\_interface\_ids | One or more network interfaces for the VPC Endpoint for S3 interface. |
984988
| vpc\_endpoint\_sagemaker\_api\_dns\_entry | The DNS entries for the VPC Endpoint for SageMaker API. |
985989
| vpc\_endpoint\_sagemaker\_api\_id | The ID of VPC endpoint for SageMaker API |
986990
| vpc\_endpoint\_sagemaker\_api\_network\_interface\_ids | One or more network interfaces for the VPC Endpoint for SageMaker API. |

outputs.tf

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,12 +484,12 @@ output "elasticache_network_acl_arn" {
484484

485485
# VPC Endpoints
486486
output "vpc_endpoint_s3_id" {
487-
description = "The ID of VPC endpoint for S3"
487+
description = "The ID of VPC endpoint for S3 gateway"
488488
value = concat(aws_vpc_endpoint.s3.*.id, [""])[0]
489489
}
490490

491491
output "vpc_endpoint_s3_pl_id" {
492-
description = "The prefix list for the S3 VPC endpoint."
492+
description = "The prefix list for the S3 gateway VPC endpoint."
493493
value = concat(aws_vpc_endpoint.s3.*.prefix_list_id, [""])[0]
494494
}
495495

@@ -1442,6 +1442,21 @@ output "vpc_endpoint_rds_dns_entry" {
14421442
value = flatten(aws_vpc_endpoint.rds.*.dns_entry)
14431443
}
14441444

1445+
output "vpc_endpoint_s3_interface_id" {
1446+
description = "The ID of VPC endpoint for S3 interface"
1447+
value = concat(aws_vpc_endpoint.s3_interface.*.id, [""])[0]
1448+
}
1449+
1450+
output "vpc_endpoint_s3_interface_network_interface_ids" {
1451+
description = "One or more network interfaces for the VPC Endpoint for S3 interface."
1452+
value = flatten(aws_vpc_endpoint.s3_interface.*.network_interface_ids)
1453+
}
1454+
1455+
output "vpc_endpoint_s3_interface_dns_entry" {
1456+
description = "The DNS entries for the VPC Endpoint for S3 interface."
1457+
value = flatten(aws_vpc_endpoint.s3_interface.*.dns_entry)
1458+
}
1459+
14451460
# VPC flow log
14461461
output "vpc_flow_log_id" {
14471462
description = "The ID of the Flow Log resource"

variables.tf

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -347,30 +347,30 @@ variable "dynamodb_endpoint_policy" {
347347
}
348348

349349
variable "enable_s3_endpoint" {
350-
description = "Should be true if you want to provision an S3 endpoint to the VPC"
350+
description = "Should be true if you want to provision an S3 gateway endpoint to the VPC"
351351
type = bool
352352
default = false
353353
}
354354

355-
variable "s3_endpoint_type" {
356-
description = "S3 VPC endpoint type. Note - S3 Interface type support is only available on AWS provider 3.10 and later"
357-
type = string
358-
default = "Gateway"
355+
variable "enable_s3_interface_endpoint" {
356+
description = "Should be true if you want to provision an S3 interface endpoint to the VPC"
357+
type = bool
358+
default = false
359359
}
360360

361-
variable "s3_endpoint_security_group_ids" {
361+
variable "s3_interface_endpoint_security_group_ids" {
362362
description = "The ID of one or more security groups to associate with the network interface for S3 interface endpoint"
363363
type = list(string)
364364
default = []
365365
}
366366

367-
variable "s3_endpoint_subnet_ids" {
367+
variable "s3_interface_endpoint_subnet_ids" {
368368
description = "The ID of one or more subnets in which to create a network interface for S3 interface endpoint. Only a single subnet within an AZ is supported. If omitted, private subnets will be used."
369369
type = list(string)
370370
default = []
371371
}
372372

373-
variable "s3_endpoint_private_dns_enabled" {
373+
variable "s3_interface_endpoint_private_dns_enabled" {
374374
description = "Whether or not to associate a private hosted zone with the specified VPC for S3 interface endpoint"
375375
type = bool
376376
default = false

vpc-endpoints.tf

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
######################
2-
# VPC Endpoint for S3
3-
######################
1+
#####################################
2+
# VPC Endpoint for S3 - gateway type
3+
#####################################
44
data "aws_vpc_endpoint_service" "s3" {
55
count = var.create_vpc && var.enable_s3_endpoint ? 1 : 0
66

@@ -9,7 +9,7 @@ data "aws_vpc_endpoint_service" "s3" {
99
# Used for backwards compatability where `service_type` is not yet available in the provider used
1010
filter {
1111
name = "service-type"
12-
values = [var.s3_endpoint_type]
12+
values = ["Gateway"]
1313
}
1414
}
1515

@@ -18,37 +18,63 @@ resource "aws_vpc_endpoint" "s3" {
1818

1919
vpc_id = local.vpc_id
2020
service_name = data.aws_vpc_endpoint_service.s3[0].service_name
21-
vpc_endpoint_type = var.s3_endpoint_type
21+
vpc_endpoint_type = "Gateway"
2222

23-
security_group_ids = var.s3_endpoint_type == "Interface" ? var.s3_endpoint_security_group_ids : null
24-
subnet_ids = var.s3_endpoint_type == "Interface" ? coalescelist(var.s3_endpoint_subnet_ids, aws_subnet.private.*.id) : null
25-
policy = var.s3_endpoint_policy
26-
private_dns_enabled = var.s3_endpoint_type == "Interface" ? var.s3_endpoint_private_dns_enabled : null
23+
policy = var.s3_endpoint_policy
2724

2825
tags = local.vpce_tags
2926
}
3027

3128
resource "aws_vpc_endpoint_route_table_association" "private_s3" {
32-
count = var.create_vpc && var.enable_s3_endpoint && var.s3_endpoint_type == "Gateway" ? local.nat_gateway_count : 0
29+
count = var.create_vpc && var.enable_s3_endpoint ? local.nat_gateway_count : 0
3330

3431
vpc_endpoint_id = aws_vpc_endpoint.s3[0].id
3532
route_table_id = element(aws_route_table.private.*.id, count.index)
3633
}
3734

3835
resource "aws_vpc_endpoint_route_table_association" "intra_s3" {
39-
count = var.create_vpc && var.enable_s3_endpoint && length(var.intra_subnets) > 0 && var.s3_endpoint_type == "Gateway" ? 1 : 0
36+
count = var.create_vpc && var.enable_s3_endpoint && length(var.intra_subnets) > 0 ? 1 : 0
4037

4138
vpc_endpoint_id = aws_vpc_endpoint.s3[0].id
4239
route_table_id = element(aws_route_table.intra.*.id, 0)
4340
}
4441

4542
resource "aws_vpc_endpoint_route_table_association" "public_s3" {
46-
count = var.create_vpc && var.enable_s3_endpoint && var.enable_public_s3_endpoint && length(var.public_subnets) > 0 && var.s3_endpoint_type == "Gateway" ? 1 : 0
43+
count = var.create_vpc && var.enable_s3_endpoint && var.enable_public_s3_endpoint && length(var.public_subnets) > 0 ? 1 : 0
4744

4845
vpc_endpoint_id = aws_vpc_endpoint.s3[0].id
4946
route_table_id = aws_route_table.public[0].id
5047
}
5148

49+
#######################################
50+
# VPC Endpoint for S3 - interface type
51+
#######################################
52+
data "aws_vpc_endpoint_service" "s3_interface" {
53+
count = var.create_vpc && vpc_enable_s3_interface_endpoint ? 1 : 0
54+
55+
service = "s3"
56+
57+
# Used for backwards compatability where `service_type` is not yet available in the provider used
58+
filter {
59+
name = "service-type"
60+
values = ["Interface"]
61+
}
62+
}
63+
64+
resource "aws_vpc_endpoint" "s3_interface" {
65+
count = var.create_vpc && var.enable_s3_interface_endpoint ? 1 : 0
66+
67+
vpc_id = local.vpc_id
68+
service_name = data.aws_vpc_endpoint_service.s3_interface[0].service_name
69+
vpc_endpoint_type = "Interface"
70+
71+
security_group_ids = var.s3_interface_endpoint_security_group_ids
72+
subnet_ids = coalescelist(var.s3_interface_endpoint_subnet_ids, aws_subnet.private.*.id)
73+
private_dns_enabled = var.s3_interface_endpoint_private_dns_enabled
74+
75+
tags = local.vpce_tags
76+
}
77+
5278
############################
5379
# VPC Endpoint for DynamoDB
5480
############################

0 commit comments

Comments
 (0)