I like to do a dynamic function_assocation to an AWS CloudFront resource. Instead of defining each function, I did something like the below.
resource "aws_cloudfront_function" "functions" {
for_each = var.cf_lambda_functions
name = each.value.name
comment = each.value.description
runtime = each.value.runtime
publish = each.value.publish
code = each.value.code
}
and for the function_association, I did something like the below.
dynamic "function_association" {
for_each = aws_cloudfront_function.functions
content {
event_type = "viewer-request"
function_arn = each.value.arn
}
}
this gives me an error: each.value cannot be used in this context. How do you do this by passing multiple ARN of functions?
CodePudding user response:
In dynamic blocks you can't use each. Instead it should be function_association in your case:
dynamic "function_association" {
for_each = aws_cloudfront_function.functions
content {
event_type = "viewer-request"
function_arn = function_association.value.arn
}
}
