我正在尝试解析terraform状态文件的输出。
{
"version": 3,
"terraform_version": "0.9.3",
"serial": 0,
"lineage": "ae1f2572-8fa6-4977-be73-3deac7529eff",
"modules": [
{
"path": [
"root"
],
"outputs": {
"elb_dns_name": {
"sensitive": false,
"type": "string",
"value": "web-elb-1019323532.us-east-1.elb.amazonaws.com"
}
},
"resources": {},
"depends_on": []
},
{
"path": [
"root",
"elb"
],
"outputs": {
"dns_name": {
"sensitive": false,
"type": "string",
"value": "web-elb-1019323532.us-east-1.elb.amazonaws.com"
}
},
"depends_on": []
},
{
"path": [
"root",
"sg"
],
"outputs": {
"security_group_id": {
"sensitive": false,
"type": "string",
"value": "sg-5a677425"
}
},
"depends_on": []
},
{
"path": [
"root",
"web"
],
"outputs": {
"web_instance_ids": {
"sensitive": false,
"type": "string",
"value": "i-03676fa6ba43fbb9f,i-09f51a313146856cd"
},
"web_public_ips": {
"sensitive": false,
"type": "string",
"value": "34.207.194.186,34.203.236.205"
}
},
"depends_on": []
}
]
}
我想返回一个json对象,其中输出名称是键,值是输出值。就像在这个例子中。。。
{
"elb_dns_name": "web-elb-1019323532.us-east-1.elb.amazonaws.com",
"dns_name": "web-elb-1019323532.us-east-1.elb.amazonaws.com",
"security_group_id": "sg-5a677425",
"web_instance_ids": "i-03676fa6ba43fbb9f,i-09f51a313146856cd",
"web_public_ips": "34.207.194.186,34.203.236.205"
}
我只能用这个取回单个对象
.modules[] | .outputs | to_entries | map({(.key) : .value.value }) | add
{
"elb_dns_name": "web-elb-1019323532.us-east-1.elb.amazonaws.com"
}
{
"dns_name": "web-elb-1019323532.us-east-1.elb.amazonaws.com"
}
{
"security_group_id": "sg-5a677425"
}
{
"web_instance_ids": "i-03676fa6ba43fbb9f,i-09f51a313146856cd",
"web_public_ips": "34.207.194.186,34.203.236.205"
}
所以出于某种原因,我不能发布,因为stackoverflow说我有太多的代码,没有足够的细节。。。因此,现在我正在做一个日记条目,以便键入足够的内容,以便我可以点击提交按钮。。。随时。。。任何数量的字符现在。。。
好吧,当我不在工作中构建代码管道时,我真的很喜欢玩dota2。只是我觉得我在这方面很差劲。我的意思是,我有1200个小时的游戏时间,但我仍然像1.5公里的MMR垃圾。