From 02c1935a12c889a029bc0a571410f19eb39bbab1 Mon Sep 17 00:00:00 2001 From: Maksym Vlasov Date: Fri, 22 Mar 2024 15:34:42 +0200 Subject: [PATCH] fix(`terraform_providers_lock`): Require `terraform init` (and `terraform_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 --- .pre-commit-hooks.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml index 0942ddfa7..cbe506dd3 100644 --- a/.pre-commit-hooks.yaml +++ b/.pre-commit-hooks.yaml @@ -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