Skip to content

Commit

Permalink
bug: Allows supplying the VPC ID to prevent it having to obtain it vi…
Browse files Browse the repository at this point in the history
…a data resource. This fixes the recreation of the SG because of that.

Signed-off-by: Stefan Wessels Beljaars <[email protected]>
  • Loading branch information
stefanwb committed Nov 9, 2023
1 parent dba1f49 commit 283b753
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

0 comments on commit 283b753

Please sign in to comment.