Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Lambda Terraform 12-无法在outputs.tf中放置[count.index]_Lambda_Terraform_Terraform Provider Aws - Fatal编程技术网

Lambda Terraform 12-无法在outputs.tf中放置[count.index]

Lambda Terraform 12-无法在outputs.tf中放置[count.index],lambda,terraform,terraform-provider-aws,Lambda,Terraform,Terraform Provider Aws,我对terraform模块化部署是个新手,我正在尝试在负载平衡器后面部署aws lambda。之前,我在尝试执行“terraform验证”时从目标组模块收到这些错误消息 是的,我按照建议的消息将[count.index]放在目标组模块中的依赖项资源上。然而,当我尝试执行“terraform validate”时,它现在给了我指令,让我也在目标组模块的输出文件上添加。传达这一信息: Error: Missing resource instance key on ../modules/targ

我对terraform模块化部署是个新手,我正在尝试在负载平衡器后面部署aws lambda。之前,我在尝试执行“terraform验证”时从目标组模块收到这些错误消息

是的,我按照建议的消息将[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]
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.
因此,正如建议的那样,我再次以这种格式修改了输出文件

output "target_arn" {
 value ="${aws_alb_target_group.lambda[count.index].arn}"
}
那么我现在得到的信息是:

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]
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)
}
另一种指定方法

output "event_bus_arn" {
    value = element(concat(aws_cloudwatch_event_bus.event_bus.*.arn, [""]), 0)
}