Import Existing AWS Infrastructure

Does anyone know what is the best way to import existing AWS infrastructure into Terraform?

Any ideas or help would be much appreciated.

Most resources allow you to use terraform import

With this command ‘terraform import’ would take a very long time to import all the resources. Also, from what I read it only imports the state file. I’m looking to import all the resources without doing it one by one.

As my perspective, the suitable way is to import certain resources with aws-cli inside bash script.

You can write scripts to help you if you have a lot of resources to import. There are also third party toold such as terraformer.

I’m not sure what you mean by “only imports the state file” - adding a resource to the state file is what puts that resource under Terraform’s control.

So the general process is:

  1. Write some code to represent the resources you are going to import
  2. Import those resources (maybe using a script/tool)

I have tried running the terraformer tool. I was able to import all the resources, but I’m getting a lot of errors when running terraform plan Error: Missing required argument and Error: Conflicting configuration arguments. If the terraformer tool is copying all of the existing resources, why would there be all of these errors?

In general none of the tools are “fire and forget”. The generally do a fair job at making things easier, but especially if you are asking them to write code (not just import things into state) they may not be fully up to date with the latest provider version and won’t be able to link resources together (or name & structure things as you might actually want).

You’ll need to review what was created and adjust things as needed until it works & is structured how you want.