File tree Expand file tree Collapse file tree 4 files changed +123
-107
lines changed Expand file tree Collapse file tree 4 files changed +123
-107
lines changed Original file line number Diff line number Diff line change @@ -42,6 +42,7 @@ Note that this example may create resources which can cost money (AWS Elastic IP
4242
4343| Name | Type |
4444| ------| ------|
45+ | [ aws_security_group.vpc_tls] ( https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group ) | resource |
4546| [ aws_iam_policy_document.dynamodb_endpoint_policy] ( https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document ) | data source |
4647| [ aws_iam_policy_document.generic_endpoint_policy] ( https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document ) | data source |
4748| [ aws_security_group.default] ( https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/security_group ) | data source |
Original file line number Diff line number Diff line change @@ -102,6 +102,7 @@ module "vpc_endpoints" {
102102 service = " ssm"
103103 private_dns_enabled = true
104104 subnet_ids = module.vpc.private_subnets
105+ security_group_ids = [aws_security_group.vpc_tls.id]
105106 },
106107 ssmmessages = {
107108 service = " ssmmessages"
@@ -127,6 +128,7 @@ module "vpc_endpoints" {
127128 service = " ec2"
128129 private_dns_enabled = true
129130 subnet_ids = module.vpc.private_subnets
131+ security_group_ids = [aws_security_group.vpc_tls.id]
130132 },
131133 ec2messages = {
132134 service = " ec2messages"
@@ -149,6 +151,7 @@ module "vpc_endpoints" {
149151 service = " kms"
150152 private_dns_enabled = true
151153 subnet_ids = module.vpc.private_subnets
154+ security_group_ids = [aws_security_group.vpc_tls.id]
152155 },
153156 codedeploy = {
154157 service = " codedeploy"
@@ -232,3 +235,19 @@ data "aws_iam_policy_document" "generic_endpoint_policy" {
232235 }
233236 }
234237}
238+
239+ resource "aws_security_group" "vpc_tls" {
240+ name_prefix = " ${ local . name } -vpc_tls"
241+ description = " Allow TLS inbound traffic"
242+ vpc_id = module. vpc . vpc_id
243+
244+ ingress {
245+ description = " TLS from VPC"
246+ from_port = 443
247+ to_port = 443
248+ protocol = " tcp"
249+ cidr_blocks = [module . vpc . vpc_cidr_block ]
250+ }
251+
252+ tags = local. tags
253+ }
Original file line number Diff line number Diff line change 1- locals {
2- endpoints = var. create ? var. endpoints : tomap ({})
3- }
4-
51# ###############################################################################
62# Endpoint(s)
73# ###############################################################################
84
95data "aws_vpc_endpoint_service" "this" {
10- for_each = local . endpoints
6+ for_each = { for k , v in var . endpoints : k => v if var . create }
117
128 service = lookup (each. value , " service" , null )
139 service_name = lookup (each. value , " service_name" , null )
@@ -19,7 +15,7 @@ data "aws_vpc_endpoint_service" "this" {
1915}
2016
2117resource "aws_vpc_endpoint" "this" {
22- for_each = local . endpoints
18+ for_each = { for k , v in var . endpoints : k => v if var . create }
2319
2420 vpc_id = var. vpc_id
2521 service_name = data. aws_vpc_endpoint_service . this [each . key ]. service_name
You can’t perform that action at this time.
0 commit comments