Automated refactoring for Terraform

Overview

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.

You might also like...
Terraform-provider-vercel - Terraform Vercel Provider With Golang

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

Terraform-grafana-dashboard - Grafana dashboard Terraform module

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

Puccini-terraform - Enable TOSCA for Terraform using Puccini

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

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

Terraform-ncloud-docs - Terraform-ncloud-docs

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

Terraform-provider-age - Age Terraform Provider with golang

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

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

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

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

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

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
    opened by raymyers 0
Owner
Craft vs Cruft
Meditations on software quality
Craft vs Cruft
kube-champ 42 Sep 22, 2022
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

Equinix 1 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

WeakPixel 39 Aug 31, 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

Martin Atkins 33 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-awsutils Terraform provider for performing various tasks that cannot be performed with the official AWS Terraform Provider from Has

Cloud Posse 22 Aug 26, 2022
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

null 0 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

HashiCorp 52 Sep 20, 2022
Terraform-provider-mailcow - Terraform provider for Mailcow

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

Owen Valentine 0 Dec 31, 2021
Terraform-provider-buddy - Terraform Buddy provider For golang

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

Buddy 1 Jan 5, 2022