Skip to content

Commit 2aca6d2

Browse files
tharun-alluantonbabenko
authored andcommitted
API gateway Endpoint (#225)
1 parent ad7164b commit 2aca6d2

File tree

4 files changed

+77
-3
lines changed

4 files changed

+77
-3
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ These types of resources are supported:
1515
* [VPN Gateway](https://www.terraform.io/docs/providers/aws/r/vpn_gateway.html)
1616
* [VPC Endpoint](https://www.terraform.io/docs/providers/aws/r/vpc_endpoint.html):
1717
* Gateway: S3, DynamoDB
18-
* Interface: EC2, SSM, EC2 Messages, SSM Messages, ECR API, ECR DKR
18+
* Interface: EC2, SSM, EC2 Messages, SSM Messages, ECR API, ECR DKR, API Gateway
1919
* [RDS DB Subnet Group](https://www.terraform.io/docs/providers/aws/r/db_subnet_group.html)
2020
* [ElastiCache Subnet Group](https://www.terraform.io/docs/providers/aws/r/elasticache_subnet_group.html)
2121
* [Redshift Subnet Group](https://www.terraform.io/docs/providers/aws/r/redshift_subnet_group.html)
@@ -133,7 +133,7 @@ If `one_nat_gateway_per_az = true` and `single_nat_gateway = false`, then the mo
133133
By default, if NAT Gateways are enabled, private subnets will be configured with routes for Internet traffic that point at the NAT Gateways configured by use of the above options.
134134

135135
If you need private subnets that should have no Internet routing (in the sense of [RFC1918 Category 1 subnets](https://tools.ietf.org/html/rfc1918)), `intra_subnets` should be specified. An example use case is configuration of AWS Lambda functions within a VPC, where AWS Lambda functions only need to pass traffic to internal resources or VPC endpoints for AWS services.
136-
136+
137137
Since AWS Lambda functions allocate Elastic Network Interfaces in proportion to the traffic received ([read more](https://docs.aws.amazon.com/lambda/latest/dg/vpc.html)), it can be useful to allocate a large private subnet for such allocations, while keeping the traffic they generate entirely internal to the VPC.
138138

139139
You can add additional tags with `intra_subnet_tags` as with other subnet types.
@@ -238,6 +238,7 @@ Terraform version 0.10.3 or newer is required for this module to work.
238238
| enable\_s3\_endpoint | Should be true if you want to provision an S3 endpoint to the VPC | string | `"false"` | no |
239239
| enable\_ssm\_endpoint | Should be true if you want to provision an SSM endpoint to the VPC | string | `"false"` | no |
240240
| enable\_ssmmessages\_endpoint | Should be true if you want to provision a SSMMESSAGES endpoint to the VPC | string | `"false"` | no |
241+
| enable\_apigw\_endpoint | Should be true if you want to provision a API Gateway endpoint to the VPC | string | `"false"` | no |
241242
| enable\_vpn\_gateway | Should be true if you want to create a new VPN Gateway resource and attach it to the VPC | string | `"false"` | no |
242243
| external\_nat\_ip\_ids | List of EIP IDs to be assigned to the NAT Gateways (used in combination with reuse_nat_ips) | list | `[]` | no |
243244
| igw\_tags | Additional tags for the internet gateway | map | `{}` | no |
@@ -271,8 +272,10 @@ Terraform version 0.10.3 or newer is required for this module to work.
271272
| single\_nat\_gateway | Should be true if you want to provision a single shared NAT Gateway across all of your private networks | string | `"false"` | no |
272273
| ssm\_endpoint\_private\_dns\_enabled | Whether or not to associate a private hosted zone with the specified VPC for SSM endpoint | string | `"false"` | no |
273274
| ssm\_endpoint\_security\_group\_ids | The ID of one or more security groups to associate with the network interface for SSM endpoint | list | `[]` | no |
275+
| apigw\_endpoint\_security\_group\_ids | The ID of one or more security groups to associate with the network interface for API Gateway endpoint | list | `[]` | no |
274276
| ssm\_endpoint\_subnet\_ids | The ID of one or more subnets in which to create a network interface for SSM endpoint. Only a single subnet within an AZ is supported. If omitted, private subnets will be used. | list | `[]` | no |
275277
| ssmmessages\_endpoint\_private\_dns\_enabled | Whether or not to associate a private hosted zone with the specified VPC for SSMMESSAGES endpoint | string | `"false"` | no |
278+
| apigw\_endpoint\_private\_dns\_enabled | Whether or not to associate a private hosted zone with the specified VPC for API Gateway endpoint | string | `"false"` | no |
276279
| ssmmessages\_endpoint\_security\_group\_ids | The ID of one or more security groups to associate with the network interface for SSMMESSAGES endpoint | list | `[]` | no |
277280
| ssmmessages\_endpoint\_subnet\_ids | The ID of one or more subnets in which to create a network interface for SSMMESSAGES endpoint. Only a single subnet within an AZ is supported. If omitted, private subnets will be used. | list | `[]` | no |
278281
| tags | A map of tags to add to all resources | map | `{}` | no |
@@ -369,4 +372,3 @@ Module is maintained by [Anton Babenko](https://github.com/antonbabenko) with he
369372
## License
370373

371374
Apache 2 Licensed. See LICENSE for full details.
372-
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
provider "aws" {
2+
region = "us-east-1"
3+
}
4+
5+
data "aws_security_group" "default" {
6+
name = "default"
7+
vpc_id = "${module.vpc.vpc_id}"
8+
}
9+
10+
module "vpc" {
11+
source = "../../"
12+
13+
name = "complete-example"
14+
15+
cidr = "10.15.0.0/16"
16+
17+
azs = ["us-east-1a"]
18+
private_subnets = ["10.15.1.0/24"]
19+
20+
# VPC endpoint for API gateway
21+
enable_apigw_endpoint = true
22+
apigw_endpoint_security_group_ids = ["${data.aws_security_group.default.id}"]
23+
apigw_endpoint_private_dns_enabled = true
24+
25+
tags = {
26+
Owner = "user"
27+
Environment = "test"
28+
Name = "test-224"
29+
}
30+
}

main.tf

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,28 @@ resource "aws_vpc_endpoint" "ecr_dkr" {
530530
private_dns_enabled = "${var.ecr_dkr_endpoint_private_dns_enabled}"
531531
}
532532

533+
#######################
534+
# VPC Endpoint for API Gateway
535+
#######################
536+
data "aws_vpc_endpoint_service" "apigw" {
537+
count = "${var.create_vpc && var.enable_apigw_endpoint ? 1 : 0}"
538+
539+
service = "execute-api"
540+
}
541+
542+
resource "aws_vpc_endpoint" "apigw" {
543+
count = "${var.create_vpc && var.enable_apigw_endpoint ? 1 : 0}"
544+
545+
vpc_id = "${local.vpc_id}"
546+
service_name = "${data.aws_vpc_endpoint_service.apigw.service_name}"
547+
vpc_endpoint_type = "Interface"
548+
549+
security_group_ids = ["${var.apigw_endpoint_security_group_ids}"]
550+
subnet_ids = ["${coalescelist(var.apigw_endpoint_subnet_ids, aws_subnet.private.*.id)}"]
551+
private_dns_enabled = "${var.apigw_endpoint_private_dns_enabled}"
552+
}
553+
554+
533555
##########################
534556
# Route table association
535557
##########################

variables.tf

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,26 @@ variable "enable_ssmmessages_endpoint" {
208208
default = false
209209
}
210210

211+
variable "enable_apigw_endpoint" {
212+
description = "Should be true if you want to provision an api gateway endpoint to the VPC"
213+
default = false
214+
}
215+
216+
variable "apigw_endpoint_security_group_ids" {
217+
description = "The ID of one or more security groups to associate with the network interface for API GW endpoint"
218+
default = []
219+
}
220+
221+
variable "apigw_endpoint_private_dns_enabled" {
222+
description = "Whether or not to associate a private hosted zone with the specified VPC for API GW endpoint"
223+
default = false
224+
}
225+
226+
variable "apigw_endpoint_subnet_ids" {
227+
description = "The ID of one or more subnets in which to create a network interface for API GW endpoint. Only a single subnet within an AZ is supported. If omitted, private subnets will be used."
228+
default = []
229+
}
230+
211231
variable "ssmmessages_endpoint_security_group_ids" {
212232
description = "The ID of one or more security groups to associate with the network interface for SSMMESSAGES endpoint"
213233
default = []

0 commit comments

Comments
 (0)