Clone AWS services to a new account

On our existing AWS account, we have the following services. These resources were generated using the console/AWS CLI.
We need to migrate these services (100+) to a new AWS account, and we will manage them using Terraform in the future. What is the most efficient way to obtain these resource definitions(Reverse engineer into Terraform) and replicate them to the new account using Terraform? Any suggestions would be greatly appreciated.

Resources are listed below.
) IAM Profile
2) IAM Role
3) lambda Function
4) S3
5) SQS

Migrating existing AWS resources to a new AWS account and managing them using Terraform involves several steps. Here’s a high-level approach to efficiently obtain resource definitions and replicate them to the new account using Terraform:

  • Inventory of Resources: Start by creating a detailed inventory of the existing resources in your old AWS account. List all the IAM profiles, roles, Lambda functions, S3 buckets, and SQS queues you want to migrate.

  • Terraform Configuration: Create a new Terraform configuration (.tf) file for each resource type you want to migrate. You will need to define the desired state of these resources in Terraform syntax.

  • Terraform State: Initialize a Terraform state management system (local or remote) for the new AWS account. This will keep track of the resources Terraform manages.

  • Import Existing Resources: Use the Terraform import command to bring the existing resources into your Terraform state. For example, to import an IAM profile, you’d run:


terraform import aws_iam_instance_profile.example arn:aws:iam::123456789012:instance-profile/my-profile

Repeat this step for each resource type you have.

  • Define Terraform Configuration: In your Terraform configuration files, define the resources’ attributes and configurations to match what you want in your new AWS account. Ensure that you configure resources according to your needs and requirements.

  • Plan and Apply: Run terraform plan to see the changes Terraform will make in your new AWS account. Review the plan carefully. If everything looks good, run terraform apply to create the resources in the new account.

  • Testing and Validation: After resource creation, thoroughly test and validate that everything works as expected in the new AWS account.

  • Ongoing Management: Going forward, use Terraform to manage these resources in the new account. Any changes or updates should be made through Terraform to maintain infrastructure as code.

This process may require some manual effort to define Terraform configurations and import resources, but it ensures that you have full control over the migration process and can manage the resources efficiently using Terraform in the new AWS account.

You can also check out this AWS Solutions Architect Course to learn more about AWS Services.