tfsort

tfsort is a command-line utility that sorts Terraform variables and outputs in a .tf file.
Installation
To install tfsort, you can download the latest binary release from the releases page.
Alternatively, you can build from source by cloning the repository and running go build.
Usage
The basic usage of tfsort is as follows:
tfsort --file <path-to-tf-file> [--out <path-to-output-file>] [--dry-run]
Available flags:
--file: the path to the .tf file you want to sort. This flag is optional.
--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.
Author
This project was created by Alexander Nabokikh.
License
This software is available under the following licenses: