【问题标题】:Applying Terraform On Two Different AWS Accounts In the Same Plan在同一计划中的两个不同 AWS 账户上应用 Terraform
【发布时间】:2019-11-13 05:57:23
【问题描述】:

我们目前正在将一些 CloudFormation 模板移植到 Terraform。在其中一个模板中,我们使用带有 Lambda 函数的自定义资源。

该函数的目的是在我们的主 AWS 账户中承担一个角色;在那里管理 R53 DNS,并在那里添加一个新生成的 CloudFront dns。

我想知道是否有办法在 terraform 中执行此操作,例如:

  1. 在 dev/qa/prod 帐户上创建云端资源、alb 等
  2. 将 r53 记录集添加到主帐户

都在同一个 terraform 计划内。创建资源时可以选择 IAM 角色吗?或者选择应该创建资源的帐户?

我找到的唯一参考是here

【问题讨论】:

标签: amazon-web-services terraform amazon-iam amazon-route53


【解决方案1】:

您可以配置multiple providers(在您的情况下每个帐户一个)并为每个帐户创建一个别名。然后,您需要为每个资源指定提供者。示例:

provider "aws" {
  region  = "eu-west-1"
  profile = "profile1"
  alias   = "account1"
}

provider "aws" {
  region  = "eu-west-1"
  profile = "profile2"
  alias   = "account2"
}

resource "aws_lambda_function" "function1" {
  provider = "aws.account1" // will be created in account 1
  ...
}
resource "aws_lambda_function" "function2" {
  provider = "aws.account2" // will be created in account 2
  ...
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-29
    • 2020-06-10
    • 2020-05-04
    • 2022-12-05
    • 2019-10-13
    • 2017-03-26
    • 1970-01-01
    相关资源
    最近更新 更多