diff --git a/aws/cloudfront/-input.tf b/aws/cloudfront/-input.tf index 459e50e..5ad0973 100644 --- a/aws/cloudfront/-input.tf +++ b/aws/cloudfront/-input.tf @@ -69,6 +69,15 @@ variable "response_headers_policy_id" { type = string } +variable "default_lambda_function_associations" { + default = [] + type = list(object({ + event_type = string + lambda_arn = string + include_body = optional(bool) + })) +} + variable "tags" { default = {} type = map(string) diff --git a/aws/cloudfront/config.tf b/aws/cloudfront/config.tf index 5378ff7..c4f2414 100644 --- a/aws/cloudfront/config.tf +++ b/aws/cloudfront/config.tf @@ -39,6 +39,14 @@ resource "aws_cloudfront_distribution" "distribution" { event_type = "origin-request" lambda_arn = aws_lambda_function.redirector.qualified_arn } + dynamic "lambda_function_association" { + for_each = var.default_lambda_function_associations + content { + event_type = lambda_function_association.value.event_type + include_body = lookup(lambda_function_association.value, "include_body", null) + lambda_arn = lambda_function_association.value.lambda_arn + } + } max_ttl = 86400 min_ttl = 0 response_headers_policy_id = var.response_headers_policy_id