Terraform - 从模块创建输出,splat 运算符不起作用

sil*_*ent 6 terraform

我定义了一个带有循环的模块:

\n
module "stamp" {\n  for_each = toset(var.stamps)\n  source   = "./modules/stamp"\n  ...\n}\n
Run Code Online (Sandbox Code Playgroud)\n

由此,我尝试根据以下示例创建一个输出列表:

\n
output "stamp_locations" {\n  value = module.stamp.*.location\n}\n
Run Code Online (Sandbox Code Playgroud)\n

然而,这验证了,但terraform plan我收到错误:

\n
\xe2\x94\x82 Error: Unsupported attribute\n\xe2\x94\x82 \n\xe2\x94\x82   on output.tf line 3, in output "stamp_locations":\n\xe2\x94\x82    3:   value = module.stamp.*.location\n\xe2\x94\x82 \n\xe2\x94\x82 This object does not have an attribute named "location"\n
Run Code Online (Sandbox Code Playgroud)\n

最后只有这个有效:

\n
output "stamp_locations" {\n  value = [for instance in module.stamp : instance.location]\n}\n
Run Code Online (Sandbox Code Playgroud)\n

所以我想知道:我是否犯了任何错误,或者模块和循环不支持 splat 语法?

\n

Mar*_*cin 8

module.stamp是地图,而不是列表。以下内容应适用于您的地图:

value = values(module.stamp)[*].location 
Run Code Online (Sandbox Code Playgroud)

values将从您的module.stamp.