嗨,我有这个JSON输出保存在我的terraform状态。如何只提取我需要信息?
如果我运行terraform output -json | jq
,我会收到下面的输出:
{
"db_instance_address_ie": {
"sensitive": false,
"type": [
"object",
{
"Service1": "string",
"Service2": "string"
}
],
"value": {
"Service1": "Service1-mysql.xxxxxxxxxxxx.eu-west-1.rds.amazonaws.com",
"Service2": "Service2-mysql.xxxxxxxxxxxx.eu-west-1.rds.amazonaws.com"
}
},
"grafana_alb_endpoint_ie": {
"sensitive": false,
"type": [
"object",
{
"Service1": "string",
"Service2": "string"
}
],
"value": {
"Service1": "Service1-grafana-alb-xxxxxxxxx.eu-west-1.elb.amazonaws.com",
"Service2": "Service2-grafana-alb-xxxxxxxxx.eu-west-1.elb.amazonaws.com"
}
},
"grafana_private_key_ie": {
"sensitive": true,
"type": [
"object",
{
"Service1": "string",
"Service2": "string"
}
],
"value": {
"Service1": "-----BEGIN RSA PRIVATE KEY-----xxxxxxxx-----END RSA PRIVATE KEY-----",
"Service2": "-----BEGIN RSA PRIVATE KEY-----xxxxxxxx-----END RSA PRIVATE KEY-----"
}
},
"influxdb_password_ie": {
"sensitive": true,
"type": [
"object",
{
"Service1": "string",
"Service2": "string"
}
],
"value": {
"Service1": "********************",
"Service2": "********************"
}
},
"mysql_password_ie": {
"sensitive": true,
"type": [
"object",
{
"Service1": "string",
"Service2": "string"
}
],
"value": {
"Service1": "********************",
"Service2": "********************"
}
},
"zabbix_lb_endpoint_ie": {
"sensitive": false,
"type": [
"object",
{
"Service1": "string",
"Service2": "string"
}
],
"value": {
"Service1": "Service1-zbx-nlb-xxxxxxxxxxxx.elb.eu-west-1.amazonaws.com",
"Service2": "Service2-zbx-nlb-xxxxxxxxxxxx.elb.eu-west-1.amazonaws.com"
}
},
"zabbix_private_key_ie": {
"sensitive": true,
"type": [
"object",
{
"Service1": "string",
"Service2": "string"
}
],
"value": {
"Service1": "-----BEGIN RSA PRIVATE KEY-----xxxxxxxx-----END RSA PRIVATE KEY-----",
"Service2": "-----BEGIN RSA PRIVATE KEY-----xxxxxxxx-----END RSA PRIVATE KEY-----"
}
}
}
这是我的完整输出JSON。
我尝试使用下面的命令来显示值,例如:
terraform show -json | jq '.values.outputs.zabbix_private_key_ie[]'
但输出是:
true
{
"Service1": "-----BEGIN RSA PRIVATE KEY----------END RSA PRIVATE KEY-----",
"Service2": "-----BEGIN RSA PRIVATE KEY----------END RSA PRIVATE KEY-----"
}
[
"object",
{
"Service1": "string",
"Service2": "string"
}
]
我只需要提取Service1的值。这可能吗?
1条答案
按热度按时间c2e8gylq1#
多谢了。我用这个命令解决了:
输出为: