Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow optional definition of environment variables to Lambda@Edge #292

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions modules/lambda@edge/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ 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 = each.value.env_vars
}
}

resource "aws_lambda_permission" "allow_cloudfront" {
Expand Down
4 changes: 4 additions & 0 deletions modules/lambda@edge/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -31,6 +34,7 @@ variable "functions" {
handler = string
event_type = string
include_body = bool
env_vars = optional(map(string))
}))

validation {
Expand Down