This project helps you generate Terraform import commands from a Terraform state file. It can handle resources in root and child modules, as well as resources using count and for_each declarations.
- Python 3.x
- Make the script executable:
chmod +x tf_import_generator.py
- Run the script with the path to your Terraform state file:
By default, the generated import commands will be saved to a file called
./tf_import_generator.py /path/to/your/terraform.tfstate
import_commands.txt
. If you want to save the commands to a different file, use the--output
option:./tf_import_generator.py /path/to/your/terraform.tfstate --output my_import_commands.txt
The script will generate Terraform import commands based on the resources found in the state file and print them to the console. It will also save the commands to the specified output file.
Review the generated import commands and execute them as needed using your terminal or command prompt.
Enjoy!