From c469c12cf619e57ca4cd2dd55de7e228c34cfcff Mon Sep 17 00:00:00 2001 From: Stefan Wessels Beljaars Date: Thu, 9 Nov 2023 15:23:15 +0100 Subject: [PATCH 1/2] 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..f90a61f 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's SG is created." +} From 51faef1e30c19ba587cfc3d34cf1d6629d1ee738 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Thu, 9 Nov 2023 14:26:43 +0000 Subject: [PATCH 2/2] docs(readme): update module usage --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 95d66a0..aae5758 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,7 @@ No modules. | [tags](#input\_tags) | A mapping of tags to assign to the bucket | `map(string)` | `{}` | no | | [timeout](#input\_timeout) | The timeout of the lambda | `number` | `5` | no | | [tracing\_config\_mode](#input\_tracing\_config\_mode) | The lambda's AWS X-Ray tracing configuration | `string` | `null` | no | +| [vpc\_id](#input\_vpc\_id) | The VPC ID where this Lambda's SG is created. | `string` | `null` | no | ## Outputs