A hacked together idea of how to import aws_iam_role resources based on a list of role names, It will check AWS and terraform state for the existence of said role and generate terraform configuration if it exists in aws but not in state
if needed add your aws profile name to line 7
- cd src
- pip install boto3
- add some roles that exist and some roles that don't exist to
roles_by_name
on line 11 - specify your terraform state file (or run cd ../terraform && terraform init / plan / apply on an empty config to generate one )
- python3 main.py
This will:
- for each role_by_name
- If the role exists in aws
- AND the role does NOT exist in state
- Generate a terraform import block for it and write it to a file inside the ../terraform directory
- Use terraform to generate the configuration