Skip to content

Commit

Permalink
Allow lambda_function_associations to be set (#78)
Browse files Browse the repository at this point in the history
Co-authored-by: Paul Potsides <paul@koble.ai>
  • Loading branch information
strongpauly and Paul Potsides authored Oct 22, 2024
1 parent e28b31d commit 95dddd3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
14 changes: 14 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,20 @@ variable "cloudfront_function_association" {
default = []
}

variable "cloudfront_lambda_function_association" {
description = "(Optional - up to 2 per distribution) List containing information to associate a CF lambda_function to cloudfront. The first field is `event_type` of the CF function associated with default cache behavior, it can be origin-request or origin-response"
type = list(object({
event_type = string
lambda_arn = string
include_body = bool
}))
default = []
validation {
condition = length(var.cloudfront_lambda_function_association) <= 2
error_message = "Only up to 2 cloudfront_lambda_function_associations are allowed"
}
}

variable "cloudfront_custom_error_responses" {
description = "A list of custom error responses"
type = list(object({
Expand Down
8 changes: 8 additions & 0 deletions website.tf
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,14 @@ resource "aws_cloudfront_distribution" "website" {
function_arn = function_association.value.function_arn
}
}
dynamic "lambda_function_association" {
for_each = var.cloudfront_lambda_function_association
content {
event_type = lambda_function_association.value.event_type
lambda_arn = lambda_function_association.value.lambda_arn
include_body = lambda_function_association.value.include_body
}
}
}

dynamic "custom_error_response" {
Expand Down

0 comments on commit 95dddd3

Please sign in to comment.