Maintain Formatting of Embedded Terraform Provider Examples with terrafmt
When a Terraform provider repository ships Markdown documentation full of example configuration, those snippets are part of the product. If they drift out of style, or worse, stop parsing as valid HCL, users feel it immediately. terrafmt is a small tool that helps keep embedded Terraform examples formatted and syntactically correct in both local workflows and CI.
terrafmt scans files for embedded Terraform configuration, extracts the matching blocks, parses the HCL, formats it, and then either shows the diff or rewrites the file in place. It recognizes embedded configuration in a few very practical forms:
- Markdown documentation files with fenced
hcl,terraform, ortfblocks - Go source files that return raw strings
- Go source files that build examples with
fmt.Sprintf(...)
In other words, terrafmt is a bridge between "this is documentation" and "this is still code."