【发布时间】:2020-05-23 20:20:34
【问题描述】:
我是 terraform 模块化部署的新手,我正在尝试在负载均衡器后面部署 aws lambda。以前我在尝试执行“terraform validate”时从目标组模块收到这些错误消息
Error: Missing resource instance key
on ../modules/target-group/target-group.tf line 16, in resource "aws_lambda_permission" "lambda":
16: source_arn = aws_alb_target_group.lambda.arn
Because aws_alb_target_group.lambda has "count" set, its attributes must be
accessed on specific instances.
For example, to correlate with indices of a referring resource, use:
aws_alb_target_group.lambda[count.index]
是的,我按照建议的消息将 [count.index] 放在目标组模块中的依赖资源上。但是,当我尝试执行“terraform validate”时,它现在给了我在目标组模块的输出文件中添加的指令。发送此消息:
Error: Missing resource instance key
on ../modules/target-group/outputs.tf line 6, in output "target_arn":
6: value ="${aws_alb_target_group.lambda.arn}"
Because aws_alb_target_group.lambda has "count" set, its attributes must be
accessed on specific instances.
For example, to correlate with indices of a referring resource, use:
aws_alb_target_group.lambda[count.index]
所以我再次按照建议修改了这种格式的输出文件
output "target_arn" {
value ="${aws_alb_target_group.lambda[count.index].arn}"
}
那么我现在得到的是这条消息:
Error: Reference to "count" in non-counted context
on ../modules/target-group/outputs.tf line 6, in output "target_arn":
6: value ="${aws_alb_target_group.lambda[count.index].arn}"
The "count" object can be used only in "resource" and "data" blocks, and only
when the "count" argument is set.
他们之前添加 [count.index] 的建议不适用于输出文件。 我不再明白要调整什么,也无法查看有关如何解决问题的在线解决方案。请在这里提出需要的建议。
【问题讨论】:
标签: lambda terraform terraform-provider-aws