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.
To install tfsort
using Homebrew, run the following command:
- Add the tap
brew tap alexnabokikh/tfsort
- Install
tfsort
brew install tfsort
To install tfsort
using Chocolatey, run the following command:
choco install tfsort
To install tfsort
, you can download the latest binary release from the releases page.
Alternatively, you can build tfsort
from the source by cloning the repository and running go build
.
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.
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.
This project was created by Alexander Nabokikh.
This software is available under the following licenses: