Cross Account Resource creation using Terraform

Cross Account Setup

In this blog, we are going to create resources in multiple AWS accounts using Terraform.
OK !!! before we start you might have question why do we need to provision resources across multiple accounts.
If you look at the large organization they always have a huge infrastructure(multi-tier architecture), so its always best practice to keep your resources loosely coupled as its help in managing things in a much better manner, rather than setting up everything single account and facing challenger later.
So in this example, we have a SUB and MAIN account, we are spinning up application EC2 instance in sub-account and creating corresponding DNS entry for application in the main account using terraform.

To start with we need to a setup role in the main account that gives access to route53 service for creating records.

  1. Create trust relationship policy in main account as below :

2. Attach custom policy to above role:

3. Now in file add below configuration

4. Use the new above alias in route53 resource.

In this scenario we are assuming you already a hosted done setup in main account so using data element in we are just calling it in terraform.

Now you just need to do terraform init and apply and see a automatic entry updated in main account.

Hope this helps you guys !!!! Please let me know if something is unclear and needs to be improved.

BOOM you did it :)

Trying new things. Breaking stuff. Likes open source | DevOps | Find me on LinkedIn 🔎.