pre-commit-terraform
pre-commit-terraform copied to clipboard
Add hook for autoformat of terraform code snippets embedded in the docs
There is a utility called terrafmt that can be used to check and fix the formating of Terraform snippets embedded into usage sections in README.
How could pre-commit-terraform help solve your problem?
It would be great to have native support as a pre-commit hook.
@MaxymVlasov @antonbabenko: Can I pick the terrafmt hook? I have tried it in my system. Looks like, terrafmt does not extract terraform files and does not do inline code formatting from the README.md file if, we start the Three backquotes after 4 spaces in the README.md file. It only works, if we start the Three backquotes at column 0.
Ex:
- Works:

terrafmt blocks README.md
####### B1 @ #587
resource "aws_lambda_function" "pass" {
function_name = "test-env"
role = ""
runtime = "python3.8"
environment {
variables = {
AWS_DEFAULT_REGION = "us-west-2"
}
}
}
- Does not work

terrafmt blocks README.md
The README.md in the repository has all the inline code starting at 4 spaces. For ex: Hooks usage notes and examples , apart from checkov, all other sections defines the inline code starting at 4 spaces.
Sounds like this is the problem in terrafmt because markdown format allows having an offset.