From 283b753297947ac65e364c13b1e1585d23b10021 Mon Sep 17 00:00:00 2001 From: Stefan Wessels Beljaars Date: Thu, 9 Nov 2023 15:23:15 +0100 Subject: [PATCH] bug: Allows supplying the VPC ID to prevent it having to obtain it via data resource. This fixes the recreation of the SG because of that. Signed-off-by: Stefan Wessels Beljaars --- main.tf | 3 ++- variables.tf | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 781e8b0..78dd3f4 100644 --- a/main.tf +++ b/main.tf @@ -9,6 +9,7 @@ locals { source_code_hash = var.source_code_hash != null ? var.source_code_hash : var.filename != null ? filebase64sha256(var.filename) : null tracing_config = var.tracing_config_mode != null ? { create : true } : {} vpc_config = var.subnet_ids != null ? { create : true } : {} + vpc_id = var.vpc_id != null ? var.vpc_id : data.aws_subnet.selected[0].vpc_id } data "aws_iam_policy_document" "default" { @@ -77,7 +78,7 @@ resource "aws_security_group" "default" { name = var.security_group_name_prefix == null ? var.name : null name_prefix = var.security_group_name_prefix != null ? var.security_group_name_prefix : null description = "Security group for lambda ${var.name}" - vpc_id = data.aws_subnet.selected[0].vpc_id + vpc_id = local.vpc_id tags = var.tags lifecycle { diff --git a/variables.tf b/variables.tf index c5ec2c0..0a4b2a4 100644 --- a/variables.tf +++ b/variables.tf @@ -231,3 +231,9 @@ variable "tracing_config_mode" { default = null description = "The lambda's AWS X-Ray tracing configuration" } + +variable "vpc_id" { + type = string + default = null + description = "The VPC ID where this Lambda needs to run" +}