terrafmt

A tool for extracting or formatting Terraform configuration embedded in provider code
Install
Local Install
Use Go to install directly into your $GOBIN directory (e.g. $GOPATH/bin):
go get github.com/katbyte/terrafmt
Usage
Information about usage and options can be found by using the help command:
terrafmt help
This tool can extract terraform blocks, run terraform fmt on the blocks and display the difference or update them in place.
The tool currently supports blocks with the following start and end lines:
| start |
end |
| ```hcl |
``` |
| ```tf |
`, |
| return fmt.Sprintf(` |
`, |
| return fmt.Sprintf(` |
`) |
Use the blocks command to extract blocks from a file:

Use the diff command to see what would be formatted (files can also be piped in on stdin) :

For code files with printf verb formatting use the -f switch :

Use the fmt command to format the blocks:

One can use find and egrep to format multiple files:
find . | egrep "html.markdown" | sort | while read f; do terrafmt fmt -f $f; done
./website/docs/d/api_management.html.markdown: 136 lines & formatted 0/1 blocks!
./website/docs/d/api_management_api.html.markdown: 79 lines & formatted 0/1 blocks!
./website/docs/d/api_management_group.html.markdown: 46 lines & formatted 0/1 blocks!
./website/docs/d/api_management_product.html.markdown: 52 lines & formatted 0/1 blocks!
./website/docs/d/api_management_user.html.markdown: 48 lines & formatted 0/1 blocks!
./website/docs/d/app_service.html.markdown: 139 lines & formatted 0/1 blocks!
./website/docs/d/app_service_certificate.html.markdown: 54 lines & formatted 0/1 blocks!
./website/docs/d/app_service_certificate_order.html.markdown: 79 lines & formatted 0/1 blocks!
Use the upgrade012 command to upgrade the blocks to 0.12:

Development and Testing
This project uses Go Modules for dependency management.
Updating Dependencies
$ go get URL
$ go mod tidy
$ go mod vendor
Unit Testing
$ go test ./...
Local Install
$ go install .