Skip to content

Commit 79af68c

Browse files
Allow user to create S3 vpc gateway endpoint on pre-existing subnets (#62)
Previously if the user passes `private_subnet_ids` the code will never create the s3 vpc gateway endpoint. With this change the variable `create_private_s3_route` can be set to true to create the endpoint on the pre-existing subnets.
1 parent 88df8d5 commit 79af68c

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

customer-managed/aws/terraform/routing.tf

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@ resource "aws_route_table" "main" {
22
vpc_id = data.aws_vpc.redpanda.id
33
}
44

5+
locals {
6+
create_private_subnet_routes = local.create_private_subnets ? true : var.create_private_s3_route
7+
}
8+
59
resource "aws_route_table" "private" {
6-
count = local.create_private_subnets ? length(var.private_subnet_cidrs) : 0
10+
count = local.create_private_subnet_routes ? length(local.subnet_ids) : 0
711
vpc_id = data.aws_vpc.redpanda.id
812

913
tags = merge(
@@ -26,14 +30,14 @@ resource "aws_route_table_association" "public" {
2630
}
2731

2832
resource "aws_route_table_association" "private" {
29-
count = local.create_private_subnets ? length(var.private_subnet_cidrs) : 0
30-
subnet_id = aws_subnet.private[count.index].id
33+
count = local.create_private_subnet_routes ? length(aws_route_table.private) : 0
34+
subnet_id = local.subnet_ids[count.index]
3135
route_table_id = aws_route_table.private[count.index].id
3236
}
3337

3438
# Routes S3 traffic to the local gateway endpoint
3539
resource "aws_vpc_endpoint_route_table_association" "private_s3" {
36-
count = local.create_private_subnets ? length(var.private_subnet_cidrs) : 0
40+
count = length(aws_route_table.private)
3741
vpc_endpoint_id = aws_vpc_endpoint.s3.id
3842
route_table_id = aws_route_table.private[count.index].id
3943
}

customer-managed/aws/terraform/variables.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,3 +184,13 @@ variable "enable_redpanda_connect" {
184184
When true grants additional permissions required by Redpanda Connect.
185185
HELP
186186
}
187+
188+
variable "create_private_s3_route" {
189+
type = bool
190+
default = false
191+
description = <<-HELP
192+
Applies only when private_subnet_ids is passed. If private subnets are created externally this variable defaults
193+
to skipping creation of a VPC endpoint and route to S3 for private access to S3 buckets. Setting this variable to
194+
true will create the VPC endpoint and route to S3 for private access to S3 buckets for the passed private subnet IDs.
195+
HELP
196+
}

0 commit comments

Comments
 (0)