https://github.com/AlexNabokikh/tfsort
A CLI utility to sort Terraform variables and outputs
https://github.com/AlexNabokikh/tfsort
cli go golang terraform
Last synced: 25 days ago
JSON representation
A CLI utility to sort Terraform variables and outputs
- Host: GitHub
- URL: https://github.com/AlexNabokikh/tfsort
- Owner: AlexNabokikh
- License: apache-2.0
- Created: 2023-02-17T14:48:17.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2025-02-17T17:38:47.000Z (2 months ago)
- Last Synced: 2025-03-28T17:09:15.719Z (26 days ago)
- Topics: cli, go, golang, terraform
- Language: Go
- Homepage:
- Size: 3.04 MB
- Stars: 184
- Watchers: 1
- Forks: 7
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
- awesome-tf - tfsort - CLI utility to sort Terraform variables and outputs. (Tools / Community providers)
README
# tfsort
[](https://github.com/AlexNabokikh/tfsort/actions/workflows/ci.yml/badge.svg)
[](https://github.com/AlexNabokikh/tfsort/actions/workflows/release.yml/badge.svg)
[](https://goreportcard.com/report/github.com/AlexNabokikh/tfsort)
[](https://codeclimate.com/github/AlexNabokikh/tfsort/maintainability)
[](https://codeclimate.com/github/AlexNabokikh/tfsort/test_coverage)
`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](#installation)
- [homebrew](#homebrew)
- [chocolatey (windows)](#chocolatey-windows)
- [binary release](#binary-release)
- [from source](#from-source)
- [usage](#usage)
- [examples](#examples)## Demo

## Installation
### Homebrew
To install `tfsort` using Homebrew, run the following command:
- Add the tap
```bash
brew tap alexnabokikh/tfsort
```- Install `tfsort`
```bash
brew install tfsort
```### Chocolatey (Windows)
To install `tfsort` using Chocolatey, run the following command:
```bash
choco install tfsort
```### Binary release
To install `tfsort`, you can download the latest binary release from the [releases page](https://github.com/AlexNabokikh/tfsort/releases).
### 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:
```bash
tfsort [--out ] [--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`:
```bash
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:```bash
tfsort --file variables.tf --out sorted.tf
```This will create a new file called `sorted.tf` with the sorted resources.
```bash
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](https://www.linkedin.com/in/nabokih/).
## License
This software is available under the following licenses:
- **[Apache 2.0](https://github.com/AlexNabokikh/tfsort/blob/master/LICENSE)**