-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from Cantara/master
Add vpc endpoints
- Loading branch information
Showing
10 changed files
with
111 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
## examples/interface-endpoint | ||
|
||
Adding an interface endpoint to a VPC for an AWS service eliminates the data transfer costs to use that service but | ||
instead incurs a cost for adding ENIs in each subnet. For this reason interface endpoints are not enabled by default. | ||
|
||
This example shows how to extend the VPC module to add interface endpoints. It adds the interface endpoints | ||
necessary for using AWS Systems Manager / Session Manager to access an instances in a private subnet. The instances must | ||
have the default vpc security group associated for this to work. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
provider "aws" { | ||
version = ">= 2.17" | ||
region = var.region | ||
} | ||
|
||
data "aws_availability_zones" "main" {} | ||
|
||
locals { | ||
vpc_cidr_block = "10.100.0.0/16" | ||
public_cidr_blocks = [for k, v in data.aws_availability_zones.main.names : | ||
cidrsubnet(local.vpc_cidr_block, 4, k)] | ||
private_cidr_blocks = [for k, v in data.aws_availability_zones.main.zone_ids : | ||
cidrsubnet(local.vpc_cidr_block, 4, k + length(data.aws_availability_zones.main.names))] | ||
tags = { | ||
terraform = "true" | ||
environmemt = "dev" | ||
} | ||
} | ||
|
||
module "vpc" { | ||
source = "../../" | ||
name_prefix = var.name_prefix | ||
cidr_block = local.vpc_cidr_block | ||
availability_zones = data.aws_availability_zones.main.names | ||
private_subnet_cidrs = local.private_cidr_blocks | ||
create_nat_gateways = false | ||
enable_dns_hostnames = true | ||
tags = local.tags | ||
} | ||
|
||
resource "aws_vpc_endpoint" "ssm" { | ||
service_name = "com.amazonaws.${var.region}.ssm" | ||
vpc_id = module.vpc.vpc_id | ||
subnet_ids = compact(concat(module.vpc.private_subnet_ids, module.vpc.public_subnet_ids)) | ||
vpc_endpoint_type = "Interface" | ||
security_group_ids = [module.vpc.default_security_group_id] | ||
tags = local.tags | ||
private_dns_enabled = true | ||
} | ||
|
||
resource "aws_vpc_endpoint" "ssmmessages" { | ||
service_name = "com.amazonaws.${var.region}.ssmmessages" | ||
vpc_id = module.vpc.vpc_id | ||
subnet_ids = compact(concat(module.vpc.private_subnet_ids, module.vpc.public_subnet_ids)) | ||
vpc_endpoint_type = "Interface" | ||
security_group_ids = [module.vpc.default_security_group_id] | ||
tags = local.tags | ||
private_dns_enabled = true | ||
} | ||
|
||
resource "aws_vpc_endpoint" "ec2" { | ||
service_name = "com.amazonaws.${var.region}.ec2" | ||
vpc_id = module.vpc.vpc_id | ||
subnet_ids = compact(concat(module.vpc.private_subnet_ids, module.vpc.public_subnet_ids)) | ||
vpc_endpoint_type = "Interface" | ||
security_group_ids = [module.vpc.default_security_group_id] | ||
tags = local.tags | ||
private_dns_enabled = true | ||
} | ||
|
||
resource "aws_vpc_endpoint" "ec2messages" { | ||
service_name = "com.amazonaws.${var.region}.ec2messages" | ||
vpc_id = module.vpc.vpc_id | ||
subnet_ids = compact(concat(module.vpc.private_subnet_ids, module.vpc.public_subnet_ids)) | ||
vpc_endpoint_type = "Interface" | ||
security_group_ids = [module.vpc.default_security_group_id] | ||
tags = local.tags | ||
private_dns_enabled = true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
output "vpc_id" { | ||
value = module.vpc.vpc_id | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
variable "name_prefix" { | ||
type = string | ||
default = "vpc-basic-example" | ||
} | ||
|
||
variable "region" { | ||
type = string | ||
default = "eu-west-1" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters