0

We're currently porting some of our CloudFormation templates to Terraform. In one of these templates we use a custom resource with a Lambda function.

The purpose of the function is to assume a role in our main AWS account; where R53 DNS is managed, and add a newly generated CloudFront dns there.

I am wondering if there's a way to do this in terraform, such that:

  1. create the cloudfront resource, alb, etc on the dev/qa/prod accounts
  2. add the r53 recordset to the main account

All within the same terraform plan. Can I choose an IAM role when creating a resource? Or choose the account where the resource should be created?

The only reference I have found is here

Sam Hammamy
  • 10,819
  • 10
  • 56
  • 94

1 Answers1

4

You can configure multiple providers ( one per account in your case) and create an alias for each. Then you will need to specify the provider for each ressource. Example:

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
  ...
}
WalKh
  • 462
  • 3
  • 8