Skip to content

Commit

Permalink
Fix tfutils#301: find min-required version through -chdir
Browse files Browse the repository at this point in the history
This commit makes it possible to use `min-required` with the terraform
configuration (including the `required_version` spec) in a subdirectory
as `terraform -chdir=subdir`.

Prior to this commit, this behaviour does not work (`-chdir` cannot be
used with `tfenv`'s `terraform` wrapper & `min-required` version)
because `tfenv` expects to find the configuration in `$PWD`.
  • Loading branch information
OJFord committed Oct 26, 2021
1 parent 459d15b commit f4de36c
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions bin/tfenv
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,15 @@ done;

declare arg="${1:-""}";

log 'debug' "Setting TFENV_DIR to ${PWD}";
export TFENV_DIR="${PWD}"
for _arg in ${@:1}; do
if [[ "$_arg" == -chdir=* ]]; then
export TFENV_DIR="${PWD}/${_arg#-chdir=}";
break;
else
export TFENV_DIR="${PWD}";
fi;
done;
log 'debug' "Setting TFENV_DIR to ${TFENV_DIR}";

abort() {
log 'debug' 'Aborting...';
Expand Down

0 comments on commit f4de36c

Please sign in to comment.