From a69fb11f7da3d90138ee1b8716076c88591a3430 Mon Sep 17 00:00:00 2001 From: Marek Skrajnowski Date: Wed, 10 Mar 2021 12:17:27 +0100 Subject: [PATCH] refactor(lambda): add vpc_config block only when needed minimizes the impact of https://github.com/hashicorp/terraform-provider-aws/issues/15952 --- lambda/main.tf | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lambda/main.tf b/lambda/main.tf index e252b0d1..7b775ca9 100644 --- a/lambda/main.tf +++ b/lambda/main.tf @@ -104,9 +104,13 @@ resource "aws_lambda_function" "lambda" { } } - vpc_config { - subnet_ids = coalesce(var.subnet_ids, []) - security_group_ids = coalesce(var.security_group_ids, []) + dynamic "vpc_config" { + for_each = toset(var.subnet_ids != null || var.security_group_ids != null ? ["vpc_config"] : []) + + content { + subnet_ids = coalesce(var.subnet_ids, []) + security_group_ids = coalesce(var.security_group_ids, []) + } } tags = var.tags