0

我在 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 读取了第一个是空的,所以我问如何读取第二个?

4

1 回答 1

0

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

于 2019-12-19T21:16:33.027 回答