Commit 5a0302db authored by Alexis Deruelle's avatar Alexis Deruelle Committed by Alexis Deruelle
Browse files

fix: tf-validate: remove TF_PROJECT_DIR from path

This commit fixes an issue in the tf-validate job where a path relative
to the root module path variable was used to remove the cached
.terraform/terraform.tfstate file.

This caused issues if the project directory was overridden because we
change the working directory to this path in .tf-base leading to an
incorrect location being tested.

This commit updates the tf-validate job to use a path relative to the
current directory instead, ensuring that the file is tested and removed
from the right location regardless of the project directory override.

Fixes: #89
parent e829cf3a
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -1221,9 +1221,11 @@ tf-validate:
      # Cached backend configuration in `.terraform/terraform.tfstate` may lead to
      # authentication failure of the `terraform init` command even with `-backend=false` flag
      # see https://github.com/hashicorp/terraform/issues/33726#issuecomment-1697854309
      if [[ -f $TF_PROJECT_DIR/.terraform/terraform.tfstate ]]; then
      #
      # assumption: working dir is $TF_PROJECT_DIR, currently set in .tf-base (see #89)
      if [[ -f .terraform/terraform.tfstate ]]; then
        log_info "--- \\e[32mpre-init\\e[0m tf-validate: removing cached .terraform/terraform.tfstate to disable any preconfigured backend"
        rm "$TF_PROJECT_DIR/.terraform/terraform.tfstate"
        rm ".terraform/terraform.tfstate"
      fi
    - tf_pre_init
    - terraform init -backend=false