diff --git a/variables.tf b/variables.tf index 216f32a..279acd8 100644 --- a/variables.tf +++ b/variables.tf @@ -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({ diff --git a/website.tf b/website.tf index 60d05f6..adf4f90 100644 --- a/website.tf +++ b/website.tf @@ -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" {