gpt4 book ai didi

terraform - 如何从 terraform state show 中提取数据

转载 作者:行者123 更新时间:2023-12-05 01:29:58 24 4
gpt4 key购买 nike

我想从 terraform state show 中提取数据。根据文档,我们应该使用 terraform show -jsonhttps://www.terraform.io/docs/cli/commands/state/show.html

The output of terraform state show is intended for human consumption,not programmatic consumption. To extract state data for use in othersoftware, use terraform show -json and decode the result using thedocumented structure.

不确定如何将 terrafrom state showterrafrom show 结合使用

$ terraform state show 'packet_device.worker'
# packet_device.worker:
resource "packet_device" "worker" {
billing_cycle = "hourly"
created = "2015-12-17T00:06:56Z"
facility = "ewr1"
hostname = "prod-xyz01"
id = "6015bg2b-b8c4-4925-aad2-f0671d5d3b13"
locked = false
}

最佳答案

terraform state show 命令显示单个 Terraform 资源的信息,不支持 -json 标志。命令 terraform show 转储整个状态,并支持 -json 标志。与 terraform state show 的输出不同,terraform show -json 的输出是 documented并用于程序化消费。

如果你想获取特定资源的信息,如 terraform state show 所示,你可以从全状态 JSON 中提取它,例如使用 jq:

terraform show -json | \
jq '.values.root_module.resources[] | select(.address == "packet_device.worker") | .values'

这是否有意义取决于您要尝试做什么。

关于terraform - 如何从 terraform state show 中提取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67461595/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com