These are utlity scripts that really should be JS or TS.
Generate a terraform refactor configuration file based on the git diff of a terraform configuration file.
Currently only supports:
- Renaming resources
- Renaming modules
References:
git diff HEAD~ HEAD -- ./terraform/modules/atlantis/iam.tf | diff_refactor.py > ./terraform/modules/atlantis/iam-refactor.tf
Note
Just use git diff -- <file-path>
if you haven't committed your changes yet.
use git diff --name-only | grep .tf
to get a list of changed terraform config files.
python3 -m unittest test_diff_refactor.py
Generate a terraform refactor configuration file based on the terraform plan output.
Warning
Use git diff for better results, unless you use CDKTF and didn't write moved statements in your CDKTF code...
This is a lot more complicated and requires manual tuning once the script completed.
terraform plan -no-color > tfplan
plan_refactor.py tfplan > refactor.tf
python3 -m unittest test_plan_refactor.py