AWS Terraform为Cloudfront函数_association传递多个arn



我喜欢对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
}
}

相关内容

  • 没有找到相关文章

最新更新