Automated refactoring for Terraform

tfrefactor

Version Documentation Tests License: MPL2

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 avoid state mv in Terraform 1.1

See refactor.tf for more refactoring recipes.

Install

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

Run without installing

make

./bin/tfrefactor

Usage Examples

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

Run tests

make test

Author

👤 Ray Myers

🤝 Contributing

Contributions, issues and feature requests are welcome!

Feel free to check issues page. You can also take a look at the contributing guide.

Show your support

Give a ⭐️ if this project helped you!

support us

Acknowledgements

Built on hclwrite, a component of HashiCorp Configuration Language (HCL).

Inspiration and test helper code from hcledit by Masayuki Morita.

📝 License

Copyright © 2022 Ray Myers.

This project is MPL2 licensed.

Owner
Craft vs Cruft
Meditations on software quality
Craft vs Cruft
Similar Resources

Terraform-provider-vercel - Terraform Vercel Provider With Golang

Vercel Terraform Provider Website: https://www.terraform.io Documentation: https

Dec 14, 2022

Terraform-grafana-dashboard - Grafana dashboard Terraform module

terraform-grafana-dashboard terraform-grafana-dashboard for project Requirements

May 2, 2022

Puccini-terraform - Enable TOSCA for Terraform using Puccini

(work in progress) TOSCA for Terraform Enable TOSCA for Terraform using Puccini.

Jun 27, 2022

Terraform Provider Scaffolding (Terraform Plugin SDK)

Terraform Provider Scaffolding (Terraform Plugin SDK) This template repository is built on the Terraform Plugin SDK. The template repository built on

Feb 8, 2022

Terraform-ncloud-docs - Terraform-ncloud-docs

terraform-ncloud-docs Overview This docs help to use terraform creation server C

Oct 2, 2022

Terraform-provider-age - Age Terraform Provider with golang

Age Terraform Provider This provider lets you generate an Age key pair. Using th

Feb 15, 2022

Terraform-house - Golang Based terraform automation example using tf.json

Terraform House Manage your own terraform workflow using go language, with the b

Feb 17, 2022

LTF is a minimal, transparent Terraform wrapper. It makes Terraform projects easier to work with.

LTF Status: alpha LTF is a minimal, transparent Terraform wrapper. It makes Terraform projects easier to work with. In standard Terraform projects, th

Nov 19, 2022

Terraform Controller manages the life cycles of a terraform resource, allowing developers to self-serve dependencies in a controlled manner.

Terraform Controller manages the life cycles of a terraform resource, allowing developers to self-serve dependencies in a controlled manner.

TERRAFORM CONTROLLER Terraform Controller manages the life cycles of a terraform resource, allowing developers to self-serve dependencies in a control

Dec 15, 2022
Comments
  • Mv command to move elements across files

    Mv command to move elements across files

    • Add mv command to move elements accross files
    • Rename test workflow to CI
    • Specify default branch
    • Use filepath instead of path for portability
    • Compare using normalized newlines in tests for portability
Terraform-equinix-migration-tool - Tool to migrate code from Equinix Metal terraform provider to Equinix terraform provider

Equinix Terraform Provider Migration Tool This tool targets a terraform working

Feb 15, 2022
Terraform-in-Terraform: Execute Modules directly from the Terraform Registry

Terraform-In-Terraform Provider This provider allows running Terraform in Terraform. This might seem insane but there are some edge cases where it com

Dec 25, 2022
Terraform utility provider for constructing bash scripts that use data from a Terraform module

Terraform Bash Provider This is a Terraform utility provider which aims to robustly generate Bash scripts which refer to data that originated in Terra

Sep 6, 2022
Terraform provider to help with various AWS automation tasks (mostly all that stuff we cannot accomplish with the official AWS terraform provider)
Terraform provider to help with various AWS automation tasks (mostly all that stuff we cannot accomplish with the official AWS terraform provider)

terraform-provider-awsutils Terraform provider for performing various tasks that cannot be performed with the official AWS Terraform Provider from Has

Dec 8, 2022
Terraform Provider for Azure (Resource Manager)Terraform Provider for Azure (Resource Manager)
Terraform Provider for Azure (Resource Manager)Terraform Provider for Azure (Resource Manager)

Terraform Provider for Azure (Resource Manager) Version 2.x of the AzureRM Provider requires Terraform 0.12.x and later, but 1.0 is recommended. Terra

Oct 16, 2021
Quick start repository for creating a Terraform provider using terraform-plugin-framework

Terraform Provider Scaffolding (Terraform Plugin Framework) This template repository is built on the Terraform Plugin Framework. The template reposito

Dec 15, 2022
Terraform-provider-mailcow - Terraform provider for Mailcow

Terraform Provider Scaffolding (Terraform Plugin SDK) This template repository i

Dec 31, 2021
Terraform-provider-buddy - Terraform Buddy provider For golang

Terraform Provider for Buddy Documentation Requirements Terraform >= 1.0.11 Go >

Jan 5, 2022