我喜欢对AWS CloudFront资源执行动态function_assocation
。我没有定义每个函数,而是做了如下操作。
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
}
对于function_association
,我做了如下操作。
dynamic "function_association" {
for_each = aws_cloudfront_function.functions
content {
event_type = "viewer-request"
function_arn = each.value.arn
}
}
这给了我一个错误:each.value cannot be used in this context
。如何通过传递函数的多个ARN来实现这一点?
在动态块中,不能使用each
。相反,在您的情况下应该是function_association
:
dynamic "function_association" {
for_each = aws_cloudfront_function.functions
content {
event_type = "viewer-request"
function_arn = function_association.value.arn
}
}