Skip to content

Commit 95dddd3

Browse files
strongpaulyPaul Potsides
and
Paul Potsides
authored
Allow lambda_function_associations to be set (#78)
Co-authored-by: Paul Potsides <[email protected]>
1 parent e28b31d commit 95dddd3

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

variables.tf

+14
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,20 @@ variable "cloudfront_function_association" {
193193
default = []
194194
}
195195

196+
variable "cloudfront_lambda_function_association" {
197+
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"
198+
type = list(object({
199+
event_type = string
200+
lambda_arn = string
201+
include_body = bool
202+
}))
203+
default = []
204+
validation {
205+
condition = length(var.cloudfront_lambda_function_association) <= 2
206+
error_message = "Only up to 2 cloudfront_lambda_function_associations are allowed"
207+
}
208+
}
209+
196210
variable "cloudfront_custom_error_responses" {
197211
description = "A list of custom error responses"
198212
type = list(object({

website.tf

+8
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,14 @@ resource "aws_cloudfront_distribution" "website" {
167167
function_arn = function_association.value.function_arn
168168
}
169169
}
170+
dynamic "lambda_function_association" {
171+
for_each = var.cloudfront_lambda_function_association
172+
content {
173+
event_type = lambda_function_association.value.event_type
174+
lambda_arn = lambda_function_association.value.lambda_arn
175+
include_body = lambda_function_association.value.include_body
176+
}
177+
}
170178
}
171179

172180
dynamic "custom_error_response" {

0 commit comments

Comments
 (0)