【问题标题】:data source terraform_remote_state with workspaces带有工作区的数据源 terraform_remote_state
【发布时间】:2021-06-12 09:43:21
【问题描述】:

我正在运行带有非默认 terraform 工作区的 terraform v0.14.8。

我有一个处理我的计划和申请的亚特兰蒂斯服务器。

当我在本地克隆我的 repo 并运行我的计划时,我收到关于我的数据源的错误。我不太明白为什么在我相信执行相同操作的亚特兰蒂斯服务器上没有收到这些错误。 Atlantis 服务器也使用 tf v0.14.8。

我的地形:

data "terraform_remote_state" "route53" {
  backend = "s3"

  config = {
    key      = "web/terraform.tfstate"
    region   = "us-west-2"
    bucket   = "prod-terraform"
    role_arn = "arn:aws:iam::xxxxxxxxxx:role/atlantis"
}

在我运行本地计划之前,我会切换工作区

terraform workspace select web

# in addition I also tried
export TF_WORKSPACE=web

我的计划

teraform plan
...

Error: Unable to find remote state

  on provider.tf line 46, in data "terraform_remote_state" "route53":
  46: data "terraform_remote_state" "route53" {

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

我可以使用 env: 轻松编辑我的“密钥”,并且一切正常,但我正试图弄清楚如何在不进行调整的情况下执行此操作,因为我的亚特兰蒂斯服务器正常工作。

data "terraform_remote_state" "route53" {
  backend = "s3"

  config = {
    key      = "env:/web/web/terraform.tfstate"
    region   = "us-west-2"
    bucket   = "prod-terraform"
    role_arn = "arn:aws:iam::xxxxxxxxxx:role/atlantis"
}

【问题讨论】:

  • 该错误消息暗示您在该服务器上的用户没有您的后端的访问/身份验证/授权等。
  • 我相信这是因为它正在查找的位置没有状态文件。它不在 env:/web/web/terraform.tfstate 中查找。

标签: terraform


【解决方案1】:

您的问题似乎暗示了选择web 工作区中的哪些后端存在一些混淆。运行 terraform workspace select web 会从 current 配置(运行 Terraform 的目录)的后端选择 web 工作区,但我怀疑您的意图是从后端选择 web 后端你已经在data "terraform_remote_state" 中进行了配置。

如果是这样,您可以通过在数据源配置中设置 workspace 参数来做到这一点:

data "terraform_remote_state" "route53" {
  backend   = "s3"
  workspace = "web"

  config = {
    key      = "web/terraform.tfstate"
    region   = "us-west-2"
    bucket   = "prod-terraform"
    role_arn = "arn:aws:iam::xxxxxxxxxx:role/atlantis"
  }
}

【讨论】:

    猜你喜欢
    • 2019-10-28
    • 1970-01-01
    • 1970-01-01
    • 2017-11-12
    • 2021-06-03
    • 1970-01-01
    • 2017-12-17
    • 2021-06-02
    • 1970-01-01
    相关资源
    最近更新 更多