Skip to content

Commit 8878edc

Browse files
trouzeclaude
andauthored
chore: expand pre-commit hooks to replace Makefile targets (#33)
Add terraform_fmt/validate (commit stage), schema-drift check, and pre-push terraform test + YAML schema self-test hooks. Update terraform-docs hook to call scripts/gen-docs.sh for full-tree sync. Co-authored-by: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
1 parent 09f0aa4 commit 8878edc

1 file changed

Lines changed: 55 additions & 9 deletions

File tree

.pre-commit-config.yaml

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
repos:
2-
# Terraform formatting and documentation
2+
# Terraform formatting and validation (commit stage)
3+
- repo: https://github.com/antonbabenko/pre-commit-terraform
4+
rev: v1.96.2
5+
hooks:
6+
- id: terraform_fmt
7+
- id: terraform_validate
8+
args: [--init-args=-backend=false]
9+
10+
# Local hooks
311
- repo: local
412
hooks:
5-
- id: terraform-docs-go
6-
name: terraform-docs
7-
description: Generate terraform documentation
8-
entry: terraform-docs -c .terraform-docs.yml
13+
- id: terraform-docs
14+
name: generate terraform docs
15+
description: Generate terraform documentation for all modules
16+
entry: bash scripts/gen-docs.sh
917
language: system
10-
files: ^[^/]*\.tf$
18+
files: \.tf$
1119
exclude: ^\.terraform/.*$
20+
pass_filenames: false
1221

13-
# Terraform linting
14-
- repo: local
15-
hooks:
1622
- id: tflint
1723
name: tflint
1824
description: Run tflint to check terraform code quality
@@ -21,6 +27,46 @@ repos:
2127
files: \.tf$
2228
exclude: ^\.terraform/.*$
2329

30+
- id: schema-drift
31+
name: schema drift check
32+
entry: uv run --with PyYAML scripts/check_schema_drift.py --mapping scripts/resource_mapping.yml --schema schemas/v1.json --terraform-dir .
33+
language: system
34+
files: ^(schemas/|scripts/resource_mapping\.yml$|\.terraform\.lock\.hcl$)
35+
pass_filenames: false
36+
require_serial: true
37+
38+
- id: terraform-test-root
39+
name: terraform test (root, mock)
40+
entry: terraform test
41+
language: system
42+
pass_filenames: false
43+
stages: [pre-push]
44+
always_run: true
45+
46+
- id: terraform-test-modules
47+
name: terraform test (modules, mock)
48+
entry: bash -c 'for m in project environments jobs credentials repository; do (cd modules/$m && terraform init -backend=false && terraform test -verbose) || exit 1; done'
49+
language: system
50+
pass_filenames: false
51+
stages: [pre-push]
52+
always_run: true
53+
54+
- id: yaml-schema-valid
55+
name: yaml schema accepts valid.yml
56+
entry: bash -c 'uvx check-jsonschema==0.37.1 --schemafile schemas/v1.json validate/tests/valid.yml'
57+
language: system
58+
pass_filenames: false
59+
stages: [pre-push]
60+
always_run: true
61+
62+
- id: yaml-schema-invalid
63+
name: yaml schema rejects invalid.yml
64+
entry: bash -c '! uvx check-jsonschema==0.37.1 --schemafile schemas/v1.json validate/tests/invalid.yml'
65+
language: system
66+
pass_filenames: false
67+
stages: [pre-push]
68+
always_run: true
69+
2470
# General linting and formatting
2571
- repo: https://github.com/pre-commit/pre-commit-hooks
2672
rev: v4.4.0

0 commit comments

Comments
 (0)