Skip to content

Instantly share code, notes, and snippets.

@yezz123
Created July 2, 2024 14:57
Show Gist options
  • Save yezz123/e84f1d1a9ed175d78533d52053afef8c to your computer and use it in GitHub Desktop.
Save yezz123/e84f1d1a9ed175d78533d52053afef8c to your computer and use it in GitHub Desktop.
Terraform Setup Linting
compact: true
output: cli
quiet: true
download-external-modules: true
evaluate-variables: true
repos:
- repo: https://github.com/antonbabenko/pre-commit-terraform
rev: v1.83.5
hooks:
- id: terraform_fmt
- id: terraform_validate
- id: terraform_tflint
#- id: terraform_tfsec
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: check-yaml
- id: end-of-file-fixer
- id: check-added-large-files
- repo: https://github.com/bridgecrewio/checkov.git
rev: 2.5.11
hooks:
- id: checkov
verbose: true
args: [--soft-fail]
files: \.tf$
exclude: \.+.terraform\/.*$
require_serial: true
config {
module = true
}
plugin "terraform" {
enabled = true
preset = "recommended"
}
plugin "google" {
enabled = true
version = "0.25.0"
source = "github.com/terraform-linters/tflint-ruleset-google"
}

Installing Necessary Tools

Before proceeding, ensure you have the following tools installed and configured to be accessible via your system's PATH:

  1. gcloud
  2. kubectl
  3. terraform

For guidance on adding these tools to your PATH, refer to this Stack Overflow post for Unix-based systems and this post for Windows.

# Pre-commit hook
PRE_COMMIT_HOOK_STAMP := .git/hooks/pre-commit
pre-commit-install:
pre-commit install
pre-commit-uninstall:
pre-commit uninstall
pre-commit-run:
pre-commit run --all-files
requirements:
pip install -r requirements.txt
terraform-format:
bash hooks/fmt.sh
terraform-validate:
bash hooks/validate.sh
clean:
pre-commit-uninstall
checkov==2.5.7
pre-commit-hooks==4.5.0
pip==23.3
setuptools==68.2.2
wheel==0.41.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment