| Concern | Tool | Version Strategy |
|---|---|---|
| Linter | tflint | Latest in container |
| Formatter | terraform fmt | Latest in container |
| Formatter | terragrunt hclfmt | Latest in container (when terragrunt.hcl files present) |
| Security | tfsec | Latest in container |
| Security | checkov | Latest in container |
| Tests | terratest | Latest in container |
| Docs | terraform-docs | Latest in container |
Config file: .tflint.hcl at repository root.
Recommended .tflint.hcl:
config {
call_module_type = "local"
}
plugin "terraform" {
enabled = true
preset = "recommended"
}Add provider-specific plugins as needed (e.g., plugin "aws" for AWS resources).
No config file. Built into the Terraform CLI. Enforces the canonical HCL formatting style.
No config file required for default operation. To suppress specific findings, use inline comments:
resource "aws_s3_bucket" "example" {
#tfsec:ignore:aws-s3-enable-bucket-logging
bucket = "my-bucket"
}No config file required for default operation. To skip specific checks, use the --skip-check flag or inline comments:
resource "aws_s3_bucket" "example" {
#checkov:skip=CKV_AWS_18:Logging not required for this bucket
bucket = "my-bucket"
}Go-based infrastructure tests in the tests/ directory. Test files follow Go conventions (*_test.go).
Example test structure:
package test
import (
"testing"
"github.com/gruntwork-io/terratest/modules/terraform"
)
func TestTerraformModule(t *testing.T) {
opts := &terraform.Options{
TerraformDir: "../",
}
defer terraform.Destroy(t, opts)
terraform.InitAndApply(t, opts)
}No config file required. Terragrunt is a companion tool that runs automatically when terragrunt.hcl files are detected in the project. It formats Terragrunt HCL files to a canonical style.
# Check formatting (exits non-zero if files need formatting)
terragrunt hclfmt --terragrunt-check
# Apply formatting
terragrunt hclfmtProjects that do not use Terragrunt are unaffected — the formatter is silently skipped when no terragrunt.hcl files exist.
No config file required for default operation. Generates markdown documentation from Terraform module inputs, outputs, and descriptions.
Output is injected between markers in README.md:
<!-- BEGIN_TF_DOCS -->
<!-- END_TF_DOCS -->| Target | Command | Description |
|---|---|---|
_lint |
tflint --recursive |
Lint all Terraform configurations |
_format |
terraform fmt -check -recursive |
Check formatting (no changes) |
_format |
terragrunt hclfmt --terragrunt-check |
Check Terragrunt formatting (when terragrunt.hcl present) |
_fix |
terraform fmt -recursive |
Apply formatting fixes |
_fix |
terragrunt hclfmt |
Apply Terragrunt formatting fixes (when terragrunt.hcl present) |
_security |
tfsec . |
Security scanning for Terraform |
_security |
checkov -d . |
Policy-as-code scanning |
_test |
cd tests && go test -v -timeout 30m |
Run terratest suite |
_docs |
terraform-docs markdown table . > README.md |
Generate module documentation |
See DEVELOPMENT.md for the full Makefile contract and two-layer delegation pattern.
These run on every commit via pre-commit:
repos:
- repo: https://github.com/antonbabenko/pre-commit-terraform
rev: "" # container manages version
hooks:
- id: terraform_fmt
- id: terraform_tflint
# Uncomment if using Terragrunt:
# - id: terragrunt_fmtThese run via make security, make test, and make docs in CI pipelines. They are not configured as pre-commit hooks due to execution time:
tfsec .-- security scanningcheckov -d .-- policy-as-code scanningcd tests && go test -v -timeout 30m-- terratest suiteterraform-docs markdown table .-- documentation generation
terraform fmtis the only accepted formatter. Do not use third-party HCL formatters.- Both
tfsecandcheckovrun as part ofmake security. They are complementary: tfsec focuses on Terraform-specific misconfigurations, checkov applies broader policy-as-code rules. terraform-docsruns as part ofmake docs. It auto-generates module documentation from variable and output blocks. Place<!-- BEGIN_TF_DOCS -->/<!-- END_TF_DOCS -->markers in yourREADME.md.terratesttests are written in Go. Thetests/directory must contain ago.modfile.- All tools are pre-installed in the dev-toolchain container. Do not install them on the host.
- For cross-cutting practices (DRY, idempotency, error handling, testing, naming) and git workflow (branching, code review, conventional commits), see Coding Practices and Git Workflow.