Terraform提供给多个帐户

时间:2018-11-26 15:17:31

标签: terraform terraform-provider-aws

我使用terraform将lambda部署到一个aws帐户,将s3触发器部署到另一个帐户。因此,我创建了两个单独的文件夹,每个文件夹都具有特定帐户的状态。

但是,我想将所有内容合并到一个模板中。有可能做到吗?示例:

provider "aws" {
  profile = "${var.aws_profile}"
  region  = "eu-west-1"
}

provider "aws" {
  alias  = "bucket-trigger-account"
  region = "eu-west-1"
  profile = "${var.aws_bucket_trigger_profile}
}

我希望以下资源由aws bucket-trigger-account提供。我该怎么办?

resource "aws_s3_bucket_notification" "bucket_notification" {
  bucket = "${var.notifications_bucket}"

  lambda_function {
    lambda_function_arn = "arn:aws:lambda:eu-west-1-xxx"
    events              = ["s3:ObjectCreated:*"]
    filter_suffix       = ".test"
  }
}

1 个答案:

答案 0 :(得分:2)

发现,只需对资源使用提供者参数,就可以为该资源使用其他提供者:provider = "aws.bucket-trigger-account"