Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/pre-commit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ jobs:
run: |
pip install pre-commit
go install github.com/hashicorp/terraform-config-inspect@latest
- name: Execute generate-terraform-providers for organizational
- name: Initialize terraform modules
if: ${{ matrix.directory != '.' }}
run: |
pre-commit run generate-terraform-providers
make terraform-init
- name: Execute pre-commit
# Run only validate pre-commit check on min version supported
if: ${{ matrix.directory != '.' }}
Expand Down
20 changes: 7 additions & 13 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,19 @@ repos:
name: "Terraform Cleanup"
pass_filenames: false
language: system
entry: bash -c "find . \( -iname ".terraform*" ! -iname ".terraform-docs*" ! -path "*/test/*" \) -print0 | xargs -0 rm -r; true"
entry: make clean
- id: terraform_init
name: "Terraform Init"
pass_filenames: false
language: system
entry: make terraform-init

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
hooks:
- id: check-merge-conflict
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: local
# https://github.com/antonbabenko/pre-commit-terraform/#terraform_validate
# Adding this patch to fix organizational multi-provider terraform validate error
# 'missing provider provider["registry.terraform.io/hashicorp/google"].multiproject'
hooks:
- id: generate-terraform-providers
name: generate-terraform-providers
require_serial: true
always_run: true
entry: ./examples/organization/.generate-providers.sh
language: script
pass_filenames: false

- repo: https://github.com/antonbabenko/pre-commit-terraform
rev: v1.64.0
Expand Down
29 changes: 29 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
deps:
go install github.com/terraform-docs/[email protected]
go install github.com/hashicorp/terraform-config-inspect@latest
curl -L "`curl -s https://api.github.com/repos/terraform-linters/tflint/releases/latest | grep -o -E "https://.+?_linux_amd64.zip"`" -o tflint.zip && \
unzip tflint.zip && \
rm tflint.zip && \
Comment on lines +1 to +6
Copy link
Contributor

@wideawakening wideawakening Sep 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thaaanks! always forget that when installing requirements automatization >>>> docs.

  • should not we modify the "Install pre-commit dependencies" in the .pre-commit-config.yaml file to use this deps step?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no step in the pre-commit-config, right?

mv tflint "`go env GOPATH`/bin"

clean:
find -name ".terraform" -type d | xargs rm -rf
find -name ".terraform.lock.hcl" -type f | xargs rm -f


# https://github.com/antonbabenko/pre-commit-terraform/#terraform_validate
# Adding this patch to fix organizational multi-provider terraform validate error
# 'missing provider provider["registry.terraform.io/hashicorp/google"].multiproject'
generate-terraform-providers:
./examples/organization/.generate-providers.sh

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

lint: terraform-init
pre-commit run -a terraform_validate
pre-commit run -a terraform_tflint

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