From 96d28895c4d17f3b7abaea4f4aa04c06a97d8751 Mon Sep 17 00:00:00 2001 From: Nelson Wolf Date: Tue, 5 Dec 2023 13:40:20 -0800 Subject: [PATCH 1/2] add test environment variable --- modules/lambda@edge/main.tf | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/modules/lambda@edge/main.tf b/modules/lambda@edge/main.tf index c5187667..8d2224bd 100644 --- a/modules/lambda@edge/main.tf +++ b/modules/lambda@edge/main.tf @@ -82,6 +82,11 @@ resource "aws_lambda_function" "default" { filename = each.value.source_zip != null ? data.local_file.lambda_zip[each.key].filename : data.archive_file.lambda_zip[each.key].output_path source_code_hash = each.value.source_zip != null ? sha256(data.local_file.lambda_zip[each.key].content_base64) : data.archive_file.lambda_zip[each.key].output_base64sha256 publish = true + environment { + variables = { + test = "testvalue" + } + } } resource "aws_lambda_permission" "allow_cloudfront" { From 825716f4cbf51fe49a4233393d3858f25f26ea77 Mon Sep 17 00:00:00 2001 From: Nelson Wolf Date: Tue, 5 Dec 2023 15:32:28 -0800 Subject: [PATCH 2/2] add env_vars --- modules/lambda@edge/main.tf | 4 +--- modules/lambda@edge/variables.tf | 4 ++++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/modules/lambda@edge/main.tf b/modules/lambda@edge/main.tf index 8d2224bd..f8408a61 100644 --- a/modules/lambda@edge/main.tf +++ b/modules/lambda@edge/main.tf @@ -83,9 +83,7 @@ resource "aws_lambda_function" "default" { source_code_hash = each.value.source_zip != null ? sha256(data.local_file.lambda_zip[each.key].content_base64) : data.archive_file.lambda_zip[each.key].output_base64sha256 publish = true environment { - variables = { - test = "testvalue" - } + variables = each.value.env_vars } } diff --git a/modules/lambda@edge/variables.tf b/modules/lambda@edge/variables.tf index 83cbaf61..b223d07c 100644 --- a/modules/lambda@edge/variables.tf +++ b/modules/lambda@edge/variables.tf @@ -16,6 +16,9 @@ variable "functions" { `runtime` and `handler` correspond to the attributes of the same name in the [lambda_function](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_function) resource. + `env_vars` sets the variables key in environment variable in the [lambda_function](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_function) + resource. + `event_type` and `include_body` correspond to the attributes of the same name in the [Lambda Function association block of the cloudfront_distribution](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudfront_distribution#lambda-function-association) resource. @@ -31,6 +34,7 @@ variable "functions" { handler = string event_type = string include_body = bool + env_vars = optional(map(string)) })) validation {