The hook helps to maintain the quality and consistency of your Terraform code by automatically formatting, validating, and testing it at different stages of the development workflow.
The pre-commit hook will run terraform fmt
and terraform validate
to ensure
your Terraform code is properly formatted and valid before committing.
The pre-push hook will run terraform test
to ensure your Terraform code
passes all tests before pushing to the remote repository.
You can also run the Terraform commands directly using Lefthook. I.e.
lefthook run terraform
or lefthook run terraform --commands fmt
.
# .lefthook.yaml
remotes:
- git_url: [email protected]:boozt-platform/lefthook
ref: [tag]
configs:
# terraform validation, fmt and tests
- hooks/terraform/.lefthook.yaml
Do extend or override the commands you may do as following:
# .lefthook-local.yaml
extends:
- hooks/terraform/.lefthook.yaml
# this would override the Terraform default version
terraform:
commands:
fmt:
env:
TF_VERSION: 1.10.5