From 13b233db6ce8f669c33480fda00e76c7ee1afb73 Mon Sep 17 00:00:00 2001 From: Satyam Dudhat Date: Wed, 19 Aug 2026 15:14:21 +0530 Subject: [PATCH 1/3] feat:add a dual stack enable attribute --- EXAMPLE.md | 18 ++++++++++++++++++ README.md | 1 + main.tf | 5 +++-- variables.tf | 6 ++++++ 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/EXAMPLE.md b/EXAMPLE.md index 097c017..3818943 100644 --- a/EXAMPLE.md +++ b/EXAMPLE.md @@ -36,6 +36,24 @@ module "lambda_test" { } ``` +## Create lambda resource attached to dual-stack subnets +When the provided subnets are dual-stack (IPv4 and IPv6), set `ipv6_allowed_for_dual_stack` to `true` to allow the Lambda function to send outbound traffic over IPv6. +``` +module "lambda_test" { + source = "./lambda" + function_name = "${var.prefix}-test-lambda" + handler = "lambda.handler" + lambda_runtime = "python3.x" + s3_bucket = "${var.prefix}-test-lambda" + s3_key = "lambda.zip" + description = "Lambda resource attached to dual-stack subnets" + security_group_ids = ["sg-1234567"] + subnets = ["subnet-1", "subnet-2"] + ipv6_allowed_for_dual_stack = true + logs_retention = 14 +} +``` + ## Allow apigw to invoke lambda Api gateway will invoke the lambda function where function is created from zip file named lambda.zip uploaded in s3 bucket where key is path for zip file in the bucket. ``` diff --git a/README.md b/README.md index 2f933b8..b7dae3d 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,7 @@ No modules. | [image\_config\_entry\_point](#input\_image\_config\_entry\_point) | The ENTRYPOINT for the docker image | `list(string)` | `[]` | no | | [image\_config\_working\_directory](#input\_image\_config\_working\_directory) | The working directory for the docker image | `string` | `null` | no | | [image\_uri](#input\_image\_uri) | uri of image | `any` | `null` | no | +| [ipv6\_allowed\_for\_dual\_stack](#input\_ipv6\_allowed\_for\_dual\_stack) | Allows outbound IPv6 traffic on VPC functions attached to dual-stack subnets | `bool` | `false` | no | | [lambda\_memory](#input\_lambda\_memory) | Required Memory for Lambda function | `number` | `128` | no | | [lambda\_runtime](#input\_lambda\_runtime) | Lambda language | `any` | `null` | no | | [lambda\_timeout](#input\_lambda\_timeout) | Required Timeout for Lambda function | `number` | `5` | no | diff --git a/main.tf b/main.tf index da527a0..2a33d5c 100644 --- a/main.tf +++ b/main.tf @@ -62,8 +62,9 @@ resource "aws_lambda_function" "lambda" { dynamic "vpc_config" { for_each = var.subnets != null && var.security_group_ids != null ? [true] : [] content { - security_group_ids = var.security_group_ids - subnet_ids = var.subnets + security_group_ids = var.security_group_ids + subnet_ids = var.subnets + ipv6_allowed_for_dual_stack = var.ipv6_allowed_for_dual_stack } } diff --git a/variables.tf b/variables.tf index 950c40d..d002005 100644 --- a/variables.tf +++ b/variables.tf @@ -95,6 +95,12 @@ variable "subnets" { default = null } +variable "ipv6_allowed_for_dual_stack" { + description = "Allows outbound IPv6 traffic on VPC functions attached to dual-stack subnets" + type = bool + default = false +} + variable "logs_retention" { description = "Specifies the number of days you want to retain log events in the specified log group" type = number From 77ea06828e614ad17adeaad93926b0449f7098c6 Mon Sep 17 00:00:00 2001 From: Satyam Dudhat Date: Wed, 2 Sep 2026 23:26:54 +0530 Subject: [PATCH 2/3] feat:Add source_code_hash attribute --- EXAMPLE.md | 16 ++++++++++++++++ README.md | 1 + main.tf | 2 +- variables.tf | 6 ++++++ 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/EXAMPLE.md b/EXAMPLE.md index 3818943..a7a3eed 100644 --- a/EXAMPLE.md +++ b/EXAMPLE.md @@ -36,6 +36,22 @@ module "lambda_test" { } ``` +## Create lambda resource with source_code_hash to force redeploy on content change +When the ZIP is uploaded to S3 under a fixed key/name (so the key itself never changes), pass `source_code_hash` computed from the ZIP so Terraform detects content changes and redeploys the function. +``` +module "lambda_test" { + source = "./lambda" + function_name = "${var.prefix}-test-lambda" + handler = "lambda.handler" + lambda_runtime = "python3.x" + s3_bucket = "${var.prefix}-test-lambda" + s3_key = "lambda.zip" + source_code_hash = filebase64sha256("lambda.zip") + description = "Lambda resource with source_code_hash" + logs_retention = 14 +} +``` + ## Create lambda resource attached to dual-stack subnets When the provided subnets are dual-stack (IPv4 and IPv6), set `ipv6_allowed_for_dual_stack` to `true` to allow the Lambda function to send outbound traffic over IPv6. ``` diff --git a/README.md b/README.md index b7dae3d..dd9bc19 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,7 @@ No modules. | [s3\_bucket](#input\_s3\_bucket) | Lambda artifacts bucket | `string` | `""` | no | | [s3\_key](#input\_s3\_key) | Path of the zip file which is present in s3 bucket | `string` | `""` | no | | [security\_group\_ids](#input\_security\_group\_ids) | Security geoup id | `list(any)` | `null` | no | +| [source\_code\_hash](#input\_source\_code\_hash) | Base64-encoded SHA256 hash of the package file (e.g. filebase64sha256 on the zip being uploaded). Pass this so Terraform detects content changes and redeploys the Lambda function even when the S3 object key/ZIP name stays the same. | `string` | `null` | no | | [source\_file](#input\_source\_file) | Lambda source file | `string` | `""` | no | | [subnets](#input\_subnets) | Subnets | `list(any)` | `null` | no | | [tags](#input\_tags) | Tags | `map` | `{}` | no | diff --git a/main.tf b/main.tf index 2a33d5c..7594113 100644 --- a/main.tf +++ b/main.tf @@ -45,7 +45,7 @@ resource "aws_lambda_function" "lambda" { s3_bucket = try(data.aws_s3_object.lambda[0].bucket, null) s3_key = try(data.aws_s3_object.lambda[0].key, null) s3_object_version = try(data.aws_s3_object.lambda[0].version_id, null) - source_code_hash = try(data.aws_s3_object.lambda[0].metadata.source_code_hash, data.archive_file.lambda[0].output_base64sha256, null) + source_code_hash = var.source_code_hash filename = try(data.archive_file.lambda[0].output_path, null) image_uri = var.image_uri package_type = var.package_type diff --git a/variables.tf b/variables.tf index d002005..0903a8e 100644 --- a/variables.tf +++ b/variables.tf @@ -128,6 +128,12 @@ variable "output_path" { default = "" } +variable "source_code_hash" { + description = "Base64-encoded SHA256 hash of the package file (e.g. filebase64sha256 on the zip being uploaded). Pass this so Terraform detects content changes and redeploys the Lambda function even when the S3 object key/ZIP name stays the same." + type = string + default = null +} + variable "tags" { description = "Tags" default = {} From c22d0505e30f187194d24057c376c5031ce6a22d Mon Sep 17 00:00:00 2001 From: Satyam Dudhat Date: Wed, 2 Sep 2026 23:30:19 +0530 Subject: [PATCH 3/3] Revert "feat:Add source_code_hash attribute" This reverts commit 77ea06828e614ad17adeaad93926b0449f7098c6. --- EXAMPLE.md | 16 ---------------- README.md | 1 - main.tf | 2 +- variables.tf | 6 ------ 4 files changed, 1 insertion(+), 24 deletions(-) diff --git a/EXAMPLE.md b/EXAMPLE.md index a7a3eed..3818943 100644 --- a/EXAMPLE.md +++ b/EXAMPLE.md @@ -36,22 +36,6 @@ module "lambda_test" { } ``` -## Create lambda resource with source_code_hash to force redeploy on content change -When the ZIP is uploaded to S3 under a fixed key/name (so the key itself never changes), pass `source_code_hash` computed from the ZIP so Terraform detects content changes and redeploys the function. -``` -module "lambda_test" { - source = "./lambda" - function_name = "${var.prefix}-test-lambda" - handler = "lambda.handler" - lambda_runtime = "python3.x" - s3_bucket = "${var.prefix}-test-lambda" - s3_key = "lambda.zip" - source_code_hash = filebase64sha256("lambda.zip") - description = "Lambda resource with source_code_hash" - logs_retention = 14 -} -``` - ## Create lambda resource attached to dual-stack subnets When the provided subnets are dual-stack (IPv4 and IPv6), set `ipv6_allowed_for_dual_stack` to `true` to allow the Lambda function to send outbound traffic over IPv6. ``` diff --git a/README.md b/README.md index dd9bc19..b7dae3d 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,6 @@ No modules. | [s3\_bucket](#input\_s3\_bucket) | Lambda artifacts bucket | `string` | `""` | no | | [s3\_key](#input\_s3\_key) | Path of the zip file which is present in s3 bucket | `string` | `""` | no | | [security\_group\_ids](#input\_security\_group\_ids) | Security geoup id | `list(any)` | `null` | no | -| [source\_code\_hash](#input\_source\_code\_hash) | Base64-encoded SHA256 hash of the package file (e.g. filebase64sha256 on the zip being uploaded). Pass this so Terraform detects content changes and redeploys the Lambda function even when the S3 object key/ZIP name stays the same. | `string` | `null` | no | | [source\_file](#input\_source\_file) | Lambda source file | `string` | `""` | no | | [subnets](#input\_subnets) | Subnets | `list(any)` | `null` | no | | [tags](#input\_tags) | Tags | `map` | `{}` | no | diff --git a/main.tf b/main.tf index 7594113..2a33d5c 100644 --- a/main.tf +++ b/main.tf @@ -45,7 +45,7 @@ resource "aws_lambda_function" "lambda" { s3_bucket = try(data.aws_s3_object.lambda[0].bucket, null) s3_key = try(data.aws_s3_object.lambda[0].key, null) s3_object_version = try(data.aws_s3_object.lambda[0].version_id, null) - source_code_hash = var.source_code_hash + source_code_hash = try(data.aws_s3_object.lambda[0].metadata.source_code_hash, data.archive_file.lambda[0].output_base64sha256, null) filename = try(data.archive_file.lambda[0].output_path, null) image_uri = var.image_uri package_type = var.package_type diff --git a/variables.tf b/variables.tf index 0903a8e..d002005 100644 --- a/variables.tf +++ b/variables.tf @@ -128,12 +128,6 @@ variable "output_path" { default = "" } -variable "source_code_hash" { - description = "Base64-encoded SHA256 hash of the package file (e.g. filebase64sha256 on the zip being uploaded). Pass this so Terraform detects content changes and redeploys the Lambda function even when the S3 object key/ZIP name stays the same." - type = string - default = null -} - variable "tags" { description = "Tags" default = {}