Skip to content

Commit

Permalink
feat: added vpc endpoint resource
Browse files Browse the repository at this point in the history
  • Loading branch information
vibutigoyal committed Jun 20, 2023
1 parent 6943d39 commit 1507dff
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions _example/private-subnet/example.tf
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ module "private-subnets" {
ipv6_cidr_block = module.vpc.ipv6_cidr_block
public_subnet_ids = ["subnet-xxxxxxxxxxxx", "subnet-xxxxxxxxxxxx"]
assign_ipv6_address_on_creation = false
enable_vpc_endpoint = false

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ module "subnets" {
cidr_block = module.vpc.vpc_cidr_block
ipv6_cidr_block = module.vpc.ipv6_cidr_block
assign_ipv6_address_on_creation = false
enable_vpc_endpoint = false

}
1 change: 1 addition & 0 deletions _example/public-private-subnet/example.tf
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ module "subnets" {
cidr_block = module.vpc.vpc_cidr_block
ipv6_cidr_block = module.vpc.ipv6_cidr_block
assign_ipv6_address_on_creation = false
enable_vpc_endpoint = false

}
1 change: 1 addition & 0 deletions _example/public-subnet/example.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ module "subnets" {
cidr_block = module.vpc.vpc_cidr_block
ipv6_cidr_block = module.vpc.ipv6_cidr_block
assign_ipv6_address_on_creation = false
enable_vpc_endpoint = false

}
26 changes: 25 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,30 @@ resource "aws_route_table_association" "private" {
)
}

#Module : VPC ENDPOINT
#Description : Provides a resource to create A VPC endpoint
# to privately connect to supported AWS services and VPC endpoint services powered by AWS PrivateLink.

data "aws_region" "current" {}

resource "aws_vpc_endpoint" "s3" {
count = var.enabled == true && var.enable_vpc_endpoint == true ? 1 : 0
vpc_id = var.vpc_id
service_name = "com.amazonaws.${data.aws_region.current.name}.s3"
route_table_ids = flatten([
aws_route_table.public.*.id,
aws_route_table.private.*.id
])

tags = merge(
module.private-labels.tags,
{
Name = "endpointS3",
Environment = var.environment
}
)
}

#Module : ROUTE
#Description : Provides a resource to create a routing table entry (a route) in a VPC
# routing table.
Expand All @@ -346,7 +370,7 @@ resource "aws_route" "nat_gateway" {
resource "aws_eip" "private" {
count = local.nat_gateway_count

vpc = true
domain = "vpc"
tags = merge(
module.private-labels.tags,
{
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,10 @@ variable "assign_ipv6_address_on_creation" {
type = bool
default = false
description = "Specify true to indicate that network interfaces created in the specified subnet should be assigned an IPv6 address."
}

variable "enable_vpc_endpoint" {
type = bool
default = true
description = "enable vpc endpoint"
}

0 comments on commit 1507dff

Please sign in to comment.