【发布时间】:2020-07-30 19:38:38
【问题描述】:
我基本上是在尝试这样做:
module "california" {
source = "./themodule"
# ...
}
module "oregon" {
source = "./themodule"
# ...
}
resource "aws_globalaccelerator_endpoint_group" "world" {
# ...
dynamic "endpoint_configuration" {
for_each = [
module.california.lb,
module.oregon.lb
]
iterator = lb
content {
endpoint_id = lb.arn
weight = 100
}
}
}
# themodule/main.tf
resource "aws_lb" "lb" {
# ...
}
output "lb" {
value = aws_lb.lb
}
我正在从 Terraform 中的子模块输出 lb,并尝试在 for_each 数组中的父模块中使用它,并使用自定义的 iterator 名称。它给了我这个错误:
This object does not have an attribute named "arn".
但它确实具有该属性,它是aws_lb。我在使用这个for_each 和模块设置时做错了什么,我该如何解决?非常感谢!
如果我把它改成这个,它似乎可以工作:
resource "aws_globalaccelerator_endpoint_group" "world" {
listener_arn = aws_globalaccelerator_listener.world.id
endpoint_configuration {
endpoint_id = module.california.lb.arn
weight = 100
}
}
【问题讨论】:
-
迭代器 lb 将只有键和值属性。因此,也许您必须使用
lb.value["arn"]?
标签: amazon-web-services module iterator terraform