Commit d98f545d authored by Pierre Smeyers's avatar Pierre Smeyers
Browse files

Merge branch '38-error-while-using-implicit-tfvars-file' into 'master'

Resolve "Error while using 'Implicit tfvars' file"

Closes #38

See merge request to-be-continuous/terraform!50
parents 328415bb 7a345dea
Loading
Loading
Loading
Loading
+9 −10
Original line number Diff line number Diff line
@@ -447,6 +447,10 @@ stages:
      log_info "--- \\e[32mpre-apply\\e[0m hook (\\e[33;1m${prescript}\\e[0m) not found: skip"
    fi

    if [[ "$tf_plan" ]]; then
      log_info "--- applying upstream plan: \\e[33;1m${tf_plan}\\e[0m"
      terraform apply -auto-approve "$tf_plan"
    else
      # implicit tfvars
      env_vars=$(ls -1 "${environment_type}.env.tfvars" 2>/dev/null || ls -1 "${environment_type}.env.tfvars.json" 2>/dev/null || echo "")
      if [[ -f "$env_vars" ]]
@@ -455,11 +459,6 @@ stages:
      else
        log_info "--- no environment-specific tfvars file found: ignore"
      fi

    if [[ "$tf_plan" ]]; then
      log_info "--- applying upstream plan: \\e[33;1m${tf_plan}\\e[0m"
      terraform apply -auto-approve ${env_vars:+-var-file=${env_vars}} "$tf_plan"
    else
      log_info "--- auto plan + apply"
      # shellcheck disable=SC2154,SC2086,SC2046
      terraform apply -auto-approve ${env_vars:+-var-file=${env_vars}} $(echo "$extra_opts" | envsubst_cli) $(echo "$opts" | envsubst_cli)