我有一个JSON文件,并试图列出形状ex:“T3-纳米,T3-微,T3-小,t2.中,t3-2xlarge,r6g-介质”。
json file = info.json
{
"t3-nano" : {
"service_name" : "t3",
"existing" : 100
},
"t3-micro" : {
"service_name" : "t3",
"existing" : 1
},
"t3-small" : {
"service_name" : "t3",
"existing" : 2
},
"t2.medium" : {
"service_name" : "t2",
"existing" : 0
},
"t3-2xlarge" : {
"service_name" : "t3-2",
"existing" : 5
},
"r6g-medium" : {
"service_name" : "r6g.medium",
"existing" : 10
}}
我尝试了以下方法
locals {
service_name = flatten([for i in local.info : i[*].service_name])
shapes = flatten([for i in local.info : i[*].index])
}结果失败了
Error: Unsupported attribute
This object does not have an attribute named "index".我希望打印形状=T3-纳米,T3-微型,T3-小,t2.中,T3-2 x大,r6g-介质.如果有办法只列出形状,有人能帮忙吗?
发布于 2022-03-29 10:50:52
flatten函数和for表达式在这里都是不必要的。函数keys已经具有要实现的功能和返回值:
shapes = keys(local.info)这将分配所请求的值。
https://stackoverflow.com/questions/71657296
复制相似问题