gpt4 book ai didi

lambda - Terraform 12 - 无法将 [count.index] 放入 outputs.tf

转载 作者:行者123 更新时间:2023-12-05 02:56:48 24 4
gpt4 key购买 nike

我是 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] 的建议不适用于输出文件。我不再明白要调整什么,也看不到关于如何解决问题的在线解决方案。请建议这里需要什么。

最佳答案

使用 outputs.tf 中的格式修复了问题

output "target_arn" {
value =join("", aws_alb_target_group.lambda[*].arn)
}

关于lambda - Terraform 12 - 无法将 [count.index] 放入 outputs.tf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60117809/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com