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" +}