Skip to content

Commit ced5067

Browse files
nloutasantonbabenko
authored andcommitted
add support for KMS VPC endpoint creation (#243)
add missing list and map types in certain variables
1 parent 39f1338 commit ced5067

File tree

5 files changed

+134
-1
lines changed

5 files changed

+134
-1
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ These types of resources are supported:
1616
* [VPN Gateway](https://www.terraform.io/docs/providers/aws/r/vpn_gateway.html)
1717
* [VPC Endpoint](https://www.terraform.io/docs/providers/aws/r/vpc_endpoint.html):
1818
* Gateway: S3, DynamoDB
19-
* Interface: EC2, SSM, EC2 Messages, SSM Messages, ECR API, ECR DKR, API Gateway
19+
* Interface: EC2, SSM, EC2 Messages, SSM Messages, ECR API, ECR DKR, API Gateway, KMS
2020
* [RDS DB Subnet Group](https://www.terraform.io/docs/providers/aws/r/db_subnet_group.html)
2121
* [ElastiCache Subnet Group](https://www.terraform.io/docs/providers/aws/r/elasticache_subnet_group.html)
2222
* [Redshift Subnet Group](https://www.terraform.io/docs/providers/aws/r/redshift_subnet_group.html)
@@ -269,6 +269,7 @@ Terraform version 0.10.3 or newer is required for this module to work.
269269
| enable\_ec2messages\_endpoint | Should be true if you want to provision an EC2MESSAGES endpoint to the VPC | string | `"false"` | no |
270270
| enable\_ecr\_api\_endpoint | Should be true if you want to provision an ecr api endpoint to the VPC | string | `"false"` | no |
271271
| enable\_ecr\_dkr\_endpoint | Should be true if you want to provision an ecr dkr endpoint to the VPC | string | `"false"` | no |
272+
| enable\_kms\_endpoint | Should be true if you want to provision a KMS endpoint to the VPC | string | `"false"` | no |
272273
| enable\_nat\_gateway | Should be true if you want to provision NAT Gateways for each of your private networks | string | `"false"` | no |
273274
| enable\_public\_redshift | Controls if redshift should have public routing table | string | `"false"` | no |
274275
| enable\_s3\_endpoint | Should be true if you want to provision an S3 endpoint to the VPC | string | `"false"` | no |
@@ -286,6 +287,9 @@ Terraform version 0.10.3 or newer is required for this module to work.
286287
| intra\_subnet\_suffix | Suffix to append to intra subnets name | string | `"intra"` | no |
287288
| intra\_subnet\_tags | Additional tags for the intra subnets | map | `{}` | no |
288289
| intra\_subnets | A list of intra subnets | list | `[]` | no |
290+
| kms\_endpoint\_private\_dns\_enabled | Whether or not to associate a private hosted zone with the specified VPC for KMS endpoint | string | `"false"` | no |
291+
| kms\_endpoint\_security\_group\_ids | The ID of one or more security groups to associate with the network interface for KMS endpoint | list | `[]` | no |
292+
| kms\_endpoint\_subnet\_ids | The ID of one or more subnets in which to create a network interface for KMS endpoint. Only a single subnet within an AZ is supported. If omitted, private subnets will be used. | list | `[]` | no |
289293
| manage\_default\_network\_acl | Should be true to adopt and manage Default Network ACL | string | `"false"` | no |
290294
| manage\_default\_vpc | Should be true to adopt and manage Default VPC | string | `"false"` | no |
291295
| map\_public\_ip\_on\_launch | Should be false if you do not want to auto-assign public IP on launch | string | `"true"` | no |
@@ -398,6 +402,9 @@ Terraform version 0.10.3 or newer is required for this module to work.
398402
| vpc\_endpoint\_ec2messages\_dns\_entry | The DNS entries for the VPC Endpoint for EC2MESSAGES. |
399403
| vpc\_endpoint\_ec2messages\_id | The ID of VPC endpoint for EC2MESSAGES |
400404
| vpc\_endpoint\_ec2messages\_network\_interface\_ids | One or more network interfaces for the VPC Endpoint for EC2MESSAGES |
405+
| vpc\_endpoint\_kms\_dns\_entry | The DNS entries for the VPC Endpoint for KMS. |
406+
| vpc\_endpoint\_kms\_id | The ID of VPC endpoint for KMS |
407+
| vpc\_endpoint\_kms\_network\_interface\_ids | One or more network interfaces for the VPC Endpoint for KMS. |
401408
| vpc\_endpoint\_ecr\_api\_dns\_entry | The DNS entries for the VPC Endpoint for ECR API. |
402409
| vpc\_endpoint\_ecr\_api\_id | The ID of VPC endpoint for ECR API |
403410
| vpc\_endpoint\_ecr\_api\_network\_interface\_ids | One or more network interfaces for the VPC Endpoint for ECR API. |

examples/complete-vpc/main.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ module "vpc" {
7272
ecr_dkr_endpoint_private_dns_enabled = true
7373
ecr_dkr_endpoint_security_group_ids = ["${data.aws_security_group.default.id}"]
7474

75+
# VPC endpoint for KMS
76+
enable_kms_endpoint = true
77+
kms_endpoint_private_dns_enabled = true
78+
kms_endpoint_security_group_ids = ["${data.aws_security_group.default.id}"]
79+
# kms_endpoint_subnet_ids = ["..."]
80+
7581
tags = {
7682
Owner = "user"
7783
Environment = "staging"

main.tf

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,28 @@ resource "aws_vpc_endpoint" "apigw" {
809809
private_dns_enabled = "${var.apigw_endpoint_private_dns_enabled}"
810810
}
811811

812+
#######################
813+
# VPC Endpoint for KMS
814+
#######################
815+
data "aws_vpc_endpoint_service" "kms" {
816+
count = "${var.create_vpc && var.enable_kms_endpoint ? 1 : 0}"
817+
818+
service = "kms"
819+
}
820+
821+
resource "aws_vpc_endpoint" "kms" {
822+
count = "${var.create_vpc && var.enable_kms_endpoint ? 1 : 0}"
823+
824+
vpc_id = "${local.vpc_id}"
825+
service_name = "${data.aws_vpc_endpoint_service.kms.service_name}"
826+
vpc_endpoint_type = "Interface"
827+
828+
security_group_ids = ["${var.kms_endpoint_security_group_ids}"]
829+
subnet_ids = ["${coalescelist(var.kms_endpoint_subnet_ids, aws_subnet.private.*.id)}"]
830+
private_dns_enabled = "${var.kms_endpoint_private_dns_enabled}"
831+
}
832+
833+
812834
##########################
813835
# Route table association
814836
##########################

outputs.tf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,21 @@ output "vpc_endpoint_ec2messages_dns_entry" {
369369
value = "${flatten(aws_vpc_endpoint.ec2messages.*.dns_entry)}"
370370
}
371371

372+
output "vpc_endpoint_kms_id" {
373+
description = "The ID of VPC endpoint for KMS"
374+
value = "${element(concat(aws_vpc_endpoint.kms.*.id, list("")), 0)}"
375+
}
376+
377+
output "vpc_endpoint_kms_network_interface_ids" {
378+
description = "One or more network interfaces for the VPC Endpoint for KMS."
379+
value = "${flatten(aws_vpc_endpoint.kms.*.network_interface_ids)}"
380+
}
381+
382+
output "vpc_endpoint_kms_dns_entry" {
383+
description = "The DNS entries for the VPC Endpoint for KMS."
384+
value = "${flatten(aws_vpc_endpoint.kms.*.dns_entry)}"
385+
}
386+
372387
output "vpc_endpoint_ecr_api_id" {
373388
description = "The ID of VPC endpoint for ECR API"
374389
value = "${element(concat(aws_vpc_endpoint.ecr_api.*.id, list("")), 0)}"

0 commit comments

Comments
 (0)