Skip to content

AlexNabokikh/tfsort

Repository files navigation

tfsort

badge-gh-ci badge-gh-release go-report-card maintainability test-coverage

Logo

tfsort is a command-line utility designed for meticulous engineers who prefer to keep their Terraform variables and outputs sorted in alphabetical order.

tfsort also corrects any spacing issues between the blocks and removes any leading or trailing new lines in the file.

Contents

Demo

Demo

Installation

Homebrew

To install tfsort using Homebrew, run the following command:

  • Add the tap
brew tap alexnabokikh/tfsort
  • Install tfsort
brew install tfsort

Chocolatey (Windows)

To install tfsort using Chocolatey, run the following command:

choco install tfsort

Binary release

To install tfsort, you can download the latest binary release from the releases page.

From source

Alternatively, you can build tfsort from the source by cloning the repository and running go build.

Usage

The basic usage of tfsort is as follows:

tfsort <path-to-tf-file> [--out <path-to-output-file>] [--dry-run]

Available flags:

  • --out: the path to the output file. If not provided, tfsort will overwrite the input file.
  • --dry-run: preview the changes without altering the original file.

Examples

Here's an example of using tfsort to sort a Terraform file called main.tf:

tfsort variables.tf

This will sort the resources in variables.tf in place. You can also use the --out flag to specify an output file:

tfsort --file variables.tf --out sorted.tf

This will create a new file called sorted.tf with the sorted resources.

tfsort variables.tf --dry-run

This will print the sorted resources to the console without altering the original file.

Author

This project was created by Alexander Nabokikh.

License

This software is available under the following licenses: