Skip to content

Commit 287bfb2

Browse files
author
Tyler Ray
committed
Make VPC optional for lambda
1 parent e66a62a commit 287bfb2

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

main.tf

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ resource "aws_iam_role_policy_attachment" "lambda_policy_attach" {
224224
}
225225

226226
resource "aws_security_group" "lambda_sg" {
227+
count = var.lambda_vpc_config != null ? 1 : 0
227228
name = "${local.long_name}-lambda-sg"
228229
description = "Controls access to the Lambda"
229230
vpc_id = var.vpc_id
@@ -255,9 +256,12 @@ resource "aws_lambda_function" "api_lambda" {
255256
}
256257
}
257258

258-
vpc_config {
259-
subnet_ids = var.private_subnet_ids
260-
security_group_ids = concat([aws_security_group.lambda_sg.id], var.security_groups)
259+
dynamic "vpc_config" {
260+
for_each = var.lambda_vpc_config == null ? [] : [var.lambda_vpc_config]
261+
content {
262+
subnet_ids = lambda_vpc_config.value.subnet_ids
263+
security_group_ids = concat([aws_security_group.lambda_sg.id], lambda_vpc_config.value.security_group_ids)
264+
}
261265
}
262266
}
263267

0 commit comments

Comments
 (0)