Skip to content
This repository was archived by the owner on Sep 27, 2024. It is now read-only.

Commit 38cf5a0

Browse files
sshaikRCShanawazebushong1
authored
BATIAI-528 - Updating vpc module to add s3 endpoint (#27)
* updating vpc module to add s3 endpoint * Update main.tf Co-authored-by: Charles Bushong <charles.bushong@cms.hhs.gov> * moving vpc resource back * updating endpoint to use all non public route tables * adding conditional statement for s3 vpc endpoint creating --------- Co-authored-by: Shanawaze <shanawaze.shaik@revacomm.com> Co-authored-by: Charles Bushong <charles.bushong@cms.hhs.gov>
1 parent 928e3ea commit 38cf5a0

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

main.tf

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,19 @@ data "aws_ec2_managed_prefix_list" "cmscloud_public_pl" {
119119
data "aws_ec2_managed_prefix_list" "zscaler_pl" {
120120
count = var.zscaler_pl_exists ? 1 : 0
121121
name = "zscaler"
122+
122123
}
123124

124125
data "aws_route_table" "shared" {
125126
for_each = toset(try(data.aws_subnets.shared[0].ids, []))
126127
subnet_id = each.key
127128
}
128129

130+
data "aws_route_table" "all_non_public_route_tables" {
131+
for_each = toset(local.all_non_public_subnet_ids)
132+
subnet_id = each.key
133+
}
134+
129135

130136
locals {
131137
# shared subnet route table ids
@@ -163,6 +169,29 @@ locals {
163169
var.data_subnets_exist ? { "data" = data.aws_subnet.data } : {},
164170
var.transport_subnets_exist ? { "transport" = data.aws_subnet.transport } : {},
165171
)
172+
173+
all_non_public_subnets = merge({
174+
"private" = data.aws_subnet.private
175+
"container" = data.aws_subnet.container
176+
},
177+
var.shared_subnets_exist ? { "shared" = data.aws_subnet.shared } : {},
178+
var.data_subnets_exist ? { "data" = data.aws_subnet.data } : {},
179+
var.transport_subnets_exist ? { "transport" = data.aws_subnet.transport } : {},
180+
)
181+
182+
all_non_public_subnet_ids = flatten([for subnet_group in local.all_non_public_subnets : [for subnet in subnet_group : subnet.id]])
183+
}
184+
185+
resource "aws_vpc_endpoint" "s3" {
186+
count = var.create_s3_vpc_endpoint ? 1 : 0
187+
188+
vpc_id = data.aws_vpc.batcave_vpc.id
189+
service_name = "com.amazonaws.${var.aws_region}.s3"
190+
route_table_ids = [for route_table in data.aws_route_table.all_non_public_route_tables : route_table.id]
191+
192+
tags = {
193+
Name = "${var.project}-${var.env}-s3-endpoint"
194+
}
166195
}
167196

168197
data "aws_eips" "nat_gateways" {

variables.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ variable "project" {
66
default = "batcave"
77
}
88

9+
variable "aws_region" {
10+
default = "us-east-1"
11+
}
12+
913
variable "transport_subnets_exist" {
1014
description = "Transport subnets are used to house the NLB in situations where a service is required to be exposed to VDI users"
1115
default = false
@@ -53,3 +57,9 @@ variable "subnet_lookup_overrides" {
5357
default = {}
5458
type = map(string)
5559
}
60+
61+
variable "create_s3_vpc_endpoint" {
62+
type = bool
63+
description = "toggle on/off the creation of s3 vpc endpoint"
64+
default = true
65+
}

0 commit comments

Comments
 (0)