33 lines
953 B
HCL

######################
# VPC Endpoint for S3
######################
data "aws_vpc_endpoint_service" "s3" {
count = var.enable_s3_endpoint ? 1 : 0
service = "s3"
}
resource "aws_vpc_endpoint" "s3" {
count = var.enable_s3_endpoint ? 1 : 0
vpc_id = var.vpc_id
service_name = data.aws_vpc_endpoint_service.s3[0].service_name
#tags = local.vpce_tags
}
resource "aws_vpc_endpoint_route_table_association" "private_s3" {
count = var.enable_s3_endpoint ? 1 : 0
vpc_endpoint_id = aws_vpc_endpoint.s3[0].id
#route_table_id = element(aws_route_table.private.*.id, count.index)
route_table_id = element(var.private_route_table_ids, count.index)
}
resource "aws_vpc_endpoint_route_table_association" "public_s3" {
count = var.enable_s3_endpoint ? 1 : 0
vpc_endpoint_id = aws_vpc_endpoint.s3[0].id
#route_table_id = aws_route_table.public[0].id
route_table_id = element(var.public_route_table_ids, count.index)
}