【问题标题】:Is there a way to retrieve data from another Account in Terraform?有没有办法从 Terraform 中的另一个帐户检索数据?
【发布时间】:2021-11-16 17:21:55
【问题描述】:

我想将 Terraform 中的资源“数据”用于例如 sns 主题,但我不想在 aws-account 中寻找资源,为此我正在部署其他资源。它应该查看我的其他 aws 帐户(在同一组织中)并在那里找到资源。有没有办法做到这一点?

data "aws_sns_topic" "topic_alarms_data" {
  name = "topic_alarms"
}

【问题讨论】:

  • 好的,我找到了我会尝试的东西。您的组织资源有一个数据资源。所以这可能对我有用。 registry.terraform.io/providers/hashicorp/aws/latest/docs/…
  • 您需要使用别名配置第二个 aws 提供程序并使用该提供程序来解析数据源。
  • stackoverflow.com/a/52206826/2291321 回答你的问题了吗?
  • 如果我不必将环境分开的话,它会的。我有多个工作区,这个工作区不应该有其他环境的凭据。也许我可以创建一个 IAM 用户,对有关资源的 gwt 数据具有最低访问权限。所以我需要一段时间才能接受这个作为我问题的答案。

标签: terraform terraform-provider-aws


【解决方案1】:

使用远程帐户的凭据定义 aws 提供程序:

# Default provider that you use:
provider "aws" {
  region = var.context.aws_region
  assume_role {
    role_arn = format("arn:aws:iam::%s:role/TerraformRole", var.account_id)
  }
}

provider "aws" {
  alias = "remote"
  region = var.context.aws_region
  assume_role {
    role_arn = format("arn:aws:iam::%s:role/TerraformRole", var.remote_account_id)
  }
}

data "aws_sns_topic" "topic_alarms_data" {
  provider = aws.remote
  name     = "topic_alarms"
}

现在主题是从第二个提供者加载的。

【讨论】:

    猜你喜欢
    • 2021-12-23
    • 2020-03-17
    • 2022-11-17
    • 1970-01-01
    • 2021-08-09
    • 2019-09-28
    • 2020-12-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多