我定义了一个带有循环的模块:
module "stamp" {
for_each = toset(var.stamps)
source = "./modules/stamp"
...
}
由此我尝试创建一个基于 this example 的输出列表:
output "stamp_locations" {
value = module.stamp.*.location
}
但是,这在 terraform plan
上有效,但我收到错误:
│ Error: Unsupported attribute
│
│ on output.tf line 3, in output "stamp_locations":
│ 3: value = module.stamp.*.location
│
│ This object does not have an attribute named "location"
只有这个最终起作用了:
output "stamp_locations" {
value = [for instance in module.stamp : instance.location]
}
所以我想知道:我是不是犯了什么错误,或者模块和循环不支持 splat 语法?
最佳答案
module.stamp
是一个映射,而不是一个列表。以下内容应该适用于您的 map :
value = values(module.stamp)[*].location
values
将从您的 module.stamp
返回值列表。
关于Terraform - 使用 splat 运算符不工作从模块创建输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68358277/