Skip to content

Commit

Permalink
fix(terraform_providers_lock): Require terraform init (and `terra…
Browse files Browse the repository at this point in the history
…form_validate` hook) run when only lockfile changed (#649)

### Description of your changes

![image](https://github.com/antonbabenko/pre-commit-terraform/assets/11096782/50022937-7360-4c3b-8919-a488730c493a)

When the terraform root module contains any child module it requires `terraform init` to run to be able to successfully run the provider lock operation.

Previously, `terraform init` was in `terraform_providers_lock` hook too, but moved out to be only in `terraform_validate`, because there was little sense in trying to lock anything that was code invalid. 
If we return `terraform init` back to  `terraform_providers_lock` - major changes in providers that remove resources etc. can be successfully written to lockfile without any checks, as such checks done in `terraform_validate`

## Workaround till the release of that stuff

Add `files: (\.tf|\.tfvars|\.terraform\.lock\.hcl)$` to `terraform_validate` hook call

---

Co-authored-by: George L. Yermulnik <yz@yz.kiev.ua>
  • Loading branch information
MaxymVlasov and yermulnik committed Mar 22, 2024
1 parent 495357e commit 02c1935
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
require_serial: true
entry: hooks/terraform_validate.sh
language: script
files: (\.tf|\.tfvars)$
files: \.(tf(vars)?|terraform\.lock\.hcl)$
exclude: \.terraform/.*$

- id: terraform_providers_lock
Expand Down

0 comments on commit 02c1935

Please sign in to comment.