【问题标题】:terraform_remote_state data block syntaxterraform_remote_state 数据块语法
【发布时间】:2019-10-28 14:19:43
【问题描述】:

我正在使用 Terraform 进行 AWS 多账户设置。我有一个创建多个子帐户的主帐户,在子帐户中我引用主帐户的远程状态来检索输出值。

terraform plan 命令在测试 main.tf 中针对此配置失败:

terraform {
  required_version = ">= 0.12.0"

  backend "s3" {
    bucket = "bucketname"
    key    = "statekey.tfstate"
    region = "us-east-1"
  }
}

provider "aws" {
  region  = "us-east-1"
  version = "~> 2.7"
}

data "aws_region" "current" {}

data "terraform_remote_state" "common" {
  backend = "s3"
  config {
        bucket = "anotherbucket"
        key    = "master.tfstate"
  }
}

出现以下错误:

➜  test terraform plan

Error: Unsupported block type

  on main.tf line 20, in data "terraform_remote_state" "common":
  20:   config {

Blocks of type "config" are not expected here. Did you mean to define argument
"config"? If so, use the equals sign to assign it a value.

据我从the documentation 得知,这应该可以工作……我做错了什么?

➜  test terraform -v  
Terraform v0.12.2
+ provider.aws v2.14.0

【问题讨论】:

  • 出于好奇,您从远程状态中提取了什么?在人们使用远程状态数据源的 99% 的情况下,我建议将其替换为更本地的提供程序数据源。
  • @ydaetskcoR 我正在提取 AWS 帐号。父账户在 AWS Organizations 中为环境和项目创建多个子账户,每个项目都有自己的 Terraform 配置。

标签: terraform devops infrastructure-as-code terraform0.12+


【解决方案1】:

升级到 0.12.x 后,related document 似乎没有更新

作为错误提示,在config之后添加=


data "terraform_remote_state" "common" {
  backend = "s3"
  config = {
        bucket = "anotherbucket"
        key    = "master.tfstate"
  }
}

如果问题解决了,建议提 PR 来更新文档,这样其他人就可以避免同样的问题了。

【讨论】:

  • 有时答案只是盯着我的脸。 ??‍♂️ 这成功了。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-03-29
  • 1970-01-01
  • 2022-07-23
  • 1970-01-01
相关资源
最近更新 更多