Skip to content

Commit b2ad048

Browse files
committed
refactor: Move some code from pre-commit to makefile
1 parent 41127e2 commit b2ad048

File tree

3 files changed

+18
-20
lines changed

3 files changed

+18
-20
lines changed

.github/workflows/pre-commit.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ jobs:
6060
run: |
6161
pip install pre-commit
6262
go install github.com/hashicorp/terraform-config-inspect@latest
63-
- name: Execute generate-terraform-providers for organizational
63+
- name: Initialize terraform modules
6464
if: ${{ matrix.directory != '.' }}
6565
run: |
66-
pre-commit run generate-terraform-providers
66+
make terraform-init
6767
- name: Execute pre-commit
6868
# Run only validate pre-commit check on min version supported
6969
if: ${{ matrix.directory != '.' }}

.pre-commit-config.yaml

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,19 @@ repos:
66
name: "Terraform Cleanup"
77
pass_filenames: false
88
language: system
9-
entry: bash -c "find . \( -iname ".terraform*" ! -iname ".terraform-docs*" ! -path "*/test/*" \) -print0 | xargs -0 rm -r; true"
9+
entry: make clean
10+
- id: terraform_init
11+
name: "Terraform Init"
12+
pass_filenames: false
13+
language: system
14+
entry: make terraform-init
15+
1016
- repo: https://github.com/pre-commit/pre-commit-hooks
1117
rev: v4.0.1
1218
hooks:
1319
- id: check-merge-conflict
1420
- id: end-of-file-fixer
1521
- id: trailing-whitespace
16-
- repo: local
17-
# https://github.com/antonbabenko/pre-commit-terraform/#terraform_validate
18-
# Adding this patch to fix organizational multi-provider terraform validate error
19-
# 'missing provider provider["registry.terraform.io/hashicorp/google"].multiproject'
20-
hooks:
21-
- id: generate-terraform-providers
22-
name: generate-terraform-providers
23-
require_serial: true
24-
always_run: true
25-
entry: ./examples/organization/.generate-providers.sh
26-
language: script
27-
pass_filenames: false
2822

2923
- repo: https://github.com/antonbabenko/pre-commit-terraform
3024
rev: v1.64.0

Makefile

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,23 @@ deps:
77
mv tflint "`go env GOPATH`/bin"
88

99
clean:
10-
find -name ".terraform" -type d | xargs rm -rf
10+
find -name ".terraform" -type d | xargs rm -rf
1111
find -name ".terraform.lock.hcl" -type f | xargs rm -f
1212

13-
generate-terraform-providers:
14-
pre-commit run -a generate-terraform-providers
13+
14+
# https://github.com/antonbabenko/pre-commit-terraform/#terraform_validate
15+
# Adding this patch to fix organizational multi-provider terraform validate error
16+
# 'missing provider provider["registry.terraform.io/hashicorp/google"].multiproject'
17+
generate-terraform-providers:
18+
./examples/organization/.generate-providers.sh
1519

1620
terraform-init: generate-terraform-providers
1721
find -name "*.tf" | xargs dirname | uniq | xargs -I% -P0 sh -c 'cd %; terraform init --backend=false' 1>/dev/null
1822

19-
lint: terraform-init
23+
lint: terraform-init
2024
pre-commit run -a terraform_validate
2125
pre-commit run -a terraform_tflint
2226

2327
fmt:
24-
find -name "*.tf" | xargs dirname | uniq | xargs -I% -P0 sh -c 'cd %; terraform fmt'
28+
find -name "*.tf" | xargs dirname | uniq | xargs -I% -P0 sh -c 'cd %; terraform fmt'
2529
pre-commit run -a terraform_fmt

0 commit comments

Comments
 (0)