【问题标题】:how to read second block in tfstate with terraform?如何使用 terraform 读取 tfstate 中的第二个块?
【发布时间】:2020-04-12 10:48:57
【问题描述】:

我在 s3 上有一个远程状态,但我不知道如何访问 tfstate json 文件的第二个块。

我的 tfstate 如下所示:

{
    "version": 3,
    "terraform_version": "0.11.7",
    "serial": 1,
    "lineage": "79b7840d-5998-1ea8-2b63-ca49c289ec13",
    "modules": [
        {
            "path": [
                "root"
            ],
            "outputs": {},
            "resources": {},
            "depends_on": []
        },
        {
            "path": [
                "root",
                "vpc"
            ],
            "outputs": {
                "database_subnet_group": {
all my resources are listed here...
}

我可以通过以下代码访问它:

data "terraform_remote_state" "network" {
  backend = "s3"
  config = {
    bucket = "bakka-tfstate"
    key    = "global/network.tfstate"
    region = "eu-west-1"
  }
}

但输出

output "tfstate" {
  value = data.terraform_remote_state.network.outputs
}

什么都没显示

申请完成!资源:添加 0 个,更改 0 个,销毁 0 个。

输出:

tfstate = {}

我相信这是因为这个 tfstate 中有两个 json 块,而 terraform 读取第一个是空的,所以我问如何读取第二个?

【问题讨论】:

    标签: amazon-web-services terraform terraform-remote-state


    【解决方案1】:

    只有根输出可以通过远程状态访问。此限制为documented here。它还提出了一个解决方案 - 在产生您所指的状态的项目中,您需要将输出线程化到根输出。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-06-26
      • 1970-01-01
      • 2019-12-08
      • 1970-01-01
      • 2018-11-12
      • 1970-01-01
      • 2021-06-26
      相关资源
      最近更新 更多