Automated refactoring for Terraform.
Currently supports:
- Rename local / var / data / resource across all files in a config
- Move items or categories of items to new files.
- Diff preview of changes
- Adding
moved
blocks for resource renames to avoidstate mv
in Terraform 1.1
See refactor.tf for more refactoring recipes.
Requires Go 1.17
git clone [email protected]:craftvscruft/tfrefactor.git
cd tfrefactor
make
# Ensure ~/.local/bin is in your $PATH or copy to a directory that is.
cp bin/tfrefactor ~/.local/bin
make
./bin/tfrefactor
Display CLI help with full usage information.
tfrefactor
Rename a var from acct_id
to account_id
in the current directory
tfrefactor rename var.acct_id var.account_id
Move the var account_id
to the file variables.tf
tfrefactor mv var.account_id variables.tf
Move all data blocks to the file data.tf
tfrefactor mv data data.tf
make test
👤 Ray Myers
- YouTube: Craft vs Cruft
- Twitter: @lambdapocalypse
- GitHub: @raymyers
- LinkedIn: @cadrlife
Contributions, issues and feature requests are welcome!
Feel free to check issues page. You can also take a look at the contributing guide.
Give a ⭐️ if this project helped you!
Built on hclwrite, a component of HashiCorp Configuration Language (HCL).
Inspiration and test helper code from hcledit by Masayuki Morita.
Copyright © 2022 Ray Myers.
This project is MPL2 licensed.