select 并用JQ删除属性

select and delete attributes with JQ

信息

我有一个包含一些已弃用属性的 terraform 状态文件 (json)。

我想删除这些已弃用的属性。

我尝试使用 jqselect() && del() 但没有成功取回我的全部 json 没有弃用的属性超时。

问题

如何仅针对一种类型的资源 google_dns_record_set.

获取没有属性 timeouts 的完整 json

数据

{
  "version": 4,
  "terraform_version": "1.0.6",
  "serial": 635,
  "lineage": "6a9c2392-fdae-2b54-adcc-7366f262ffa4",
  "outputs": {"test":"test1"},
  "resources": [
  {
      "module": "module.resources",
      "mode": "data",
      "type": "google_client_config"
  },
  {
      "module": "module.xxx.module.module1[\"cluster\"]",
      "mode": "managed",
      "type": "google_dns_record_set",
      "name": "public_ip_ic_dns",
      "provider": "module.xxx.provider[\"registry.terraform.io/hashicorp/google\"]",
      "instances": [
        {
          "schema_version": 0,
          "attributes": {
            "id": "projects/xxx-xxx/managedZones/xxx--public/rrsets/*.net1.cluster.xxx--public.net.com./A",
            "managed_zone": "xxx--public",
            "name": "*.net1.cluster.xxx--public.net.com.",
            "project": "xxx-xxx",
            "rrdatas": [
              "11.22.33.44"
            ],
            "timeouts": null,
            "ttl": 300,
            "type": "A"
          },
          "sensitive_attributes": [],
          "private": "xxx",
          "dependencies": [
            "xxx"
          ]
        }
      ]
    }
  ]
}

命令

jq -r '.resources[] | select(.type=="google_dns_record_set").instances[].attributes | del(.timeouts)' data.json

del 命令拉到前面,将整个选择作为自己的过滤器包含在内

del(.resources[] | select(.type=="google_dns_record_set").instances[].attributes.timeouts)

Demo