【问题标题】:Terraform cannot read from remote stateTerraform 无法从远程状态读取
【发布时间】:2019-11-04 21:15:26
【问题描述】:

地形版本

v0.12.1

AWS 提供商版本

v2.16.0

我已经配置了 Terraform 工作区,目前我的工作区指向 dev,其中我的 VPC 和子网有一个 tfstate 文件,而我的安全组有一个不同的文件,但是当我尝试引用时vpc_id 从我的 vpc 远程 tfstate 进入我的安全组,然后我收到以下错误消息

No stored state was found for the given workspace in the given backend.

我的 s3 存储桶如下所示

nonprod-us-east-1
  |-- env
         |-- dev
                |-- vpc_subnet/tfstate
                |-- security_group/tfstate

Terraform 配置文件

安全组 tf 配置
terraform {
    backend "s3"{
        # Configuration will be injected by environment variables.
    }
}

provider "aws" {
  region = "${var.region}"
}


data "terraform_remote_state" "vpc_subnet" {
  backend = "s3"

  config = {
    bucket  = "nonprod-us-east-1"
    key     = "vpc_subnet/tfstate"
    region  = "us-east-1"
  }
}

 vpc_id = "${data.terraform_remote_state.vpc_subnet.outputs.vpc_id}"

我已经验证我的vpc_subnet/tfstate 输出具有vpc_id

VPC 子网 tf 状态的输出

outputs": {
    "private_subnet_cidr_blocks": {
      "value": [
        "10.0.3.0/24",
        "10.0.4.0/24",
        "10.0.5.0/24"
      ],
      "type": [
        "tuple",
        [
          "string",
          "string",
          "string"
        ]
      ]
    },
    "private_subnet_ids": {
      "value": [
        "subnet-042a16dd291e90add",
        "subnet-02e8322d996968a3f",
        "subnet-078f525c24015b364"
      ],
      "type": [
        "tuple",
        [
          "string",
          "string",
          "string"
        ]
      ]
    },
    "public_subnet_cidr_blocks": {
      "value": [
        "10.0.0.0/24",
        "10.0.1.0/24",
        "10.0.2.0/24"
      ],
      "type": [
        "tuple",
        [
          "string",
          "string",
          "string"
        ]
      ]
    },
    "public_subnet_ids": {
      "value": [
        "subnet-0ba92a28f6e8ddd95",
        "subnet-08efcb80bed22f4e2",
        "subnet-0b641797bfe207a0b"
      ],
      "type": [
        "tuple",
        [
          "string",
          "string",
          "string"
        ]
      ]
    },
    "vpc_id": {
      "value": "vpc-0bb7595ff05fed581",
      "type": "string"
    }
  }

预期行为

它应该能够从远程 tf 状态位置读取vpc_id

实际行为

无法从远程 tf 状态读取输出

【问题讨论】:

    标签: amazon-s3 terraform terraform-provider-aws


    【解决方案1】:

    终于整理出来了,原来是bucket key的问题,因为我使用的是Terraform工作空间所以tfstate文件是在文件夹env:/dev/vpc_subnet/tfstate下创建的,在更正bucket key之后,就可以解析tfstate文件了.

    【讨论】:

      猜你喜欢
      • 2016-11-24
      • 1970-01-01
      • 2016-12-22
      • 2020-03-21
      • 2021-12-11
      • 2019-07-28
      • 2019-11-14
      • 2021-09-10
      • 1970-01-01
      相关资源
      最近更新 更多