This repository can be used as a template for repositories carrying Terraform code.
The repository holds the following configuration files, which help develop terraform code:
.editorconfig-> EditorConfig helps maintain consistent coding styles for multiple developers working on the same project across various editors and IDEs. More about project under https://editorconfig.org/.pre-commit-config.yaml-> framework for managing and maintaining pre-commit git hooks. More about project under https://pre-commit.com/. In this config following hooks are implemented:terraform_fmt-> used to rewrite Terraform configuration files to a canonical format and style. Usingterraformcommand.terraform_validate-> validates the configuration files in a directory, referring only to the configuration and not accessing any remote services such as remote state, provider APIs, etc. Usingterraformcommand.terraform_docs-> generate documentation from Terraform code using terraform-docsterraform_tflint-> code linting using tflintend-of-file-fixer-> makes sure files end in a newline and only a newline.trailing-whitespace-> trims trailing whitespace.check-merge-conflict-> checks for files that contain merge conflict strings
.terraform-docs.yaml-> configuration file for terraform_docs.tflint.hcl-> configuration file for tflint.terraform-version-> file specifyingterraformversion which will be used by tfenv
To use configs which are attached here, you require the following tools installed on your environment:
- tfenv
- tflint
- terraform_docs
- git
- pre-commit
- native support or plugin in your favourite IDE supporting Editorconfig
The most straightforward installation on Mac OS is:
brew install git pre-commit tflint tfenv terraform-docspre-commit hooks run before any git commit is done into the repository. To run pre-commit without committing, just run:
$ pre-commit run -a
Terraform fmt............................................................Passed
Terraform validate.......................................................Passed
Terraform docs...........................................................Passed
Terraform validate with tflint...........................................Passed
Fix End of Files.........................................................Passed
Trim Trailing Whitespace.................................................Passed
Check for merge conflicts................................................Passedpre-commit is checking all hooks. In the case of terraform_fmt and terraform_docs, hooks also fix all issues (the overall result fails, but after rerunning, it should pass).
If you want to commit without triggering hooks, you can make it using option --no-verify:
git commit --no-verify