From d0d08ac63cebd23e4ee7ff58fb91ea20c398ab69 Mon Sep 17 00:00:00 2001 From: Sebastian Melchior <801781+smelchior@users.noreply.github.com> Date: Mon, 12 Jun 2023 17:59:13 +0200 Subject: [PATCH] feat: Speedup `terraform_validate` - firstly try run validate without checking is `.terraform/` is valid (#524) --- hooks/terraform_validate.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/hooks/terraform_validate.sh b/hooks/terraform_validate.sh index d0a9dfb..30e7f54 100755 --- a/hooks/terraform_validate.sh +++ b/hooks/terraform_validate.sh @@ -109,6 +109,16 @@ function per_dir_hook_unique_part { esac done + # First try `terraform validate` with the hope that all deps are + # pre-installed. That is needed for cases when `.terraform/modules` + # or `.terraform/providers` missed AND that is expected. + terraform validate "${args[@]}" 2>&1 && { + exit_code=$? + return $exit_code + } + + # In case `terraform validate` failed to execute + # - check is simple `terraform init` will help common::terraform_init 'terraform validate' "$dir_path" || { exit_code=$? return $exit_code