Skip to content

Commit

Permalink
Fix the failure to correctly handle a version requested not being ins…
Browse files Browse the repository at this point in the history
…talled. Handle it with the defaulted option to automatically install missing versions
  • Loading branch information
Zordrak committed Mar 17, 2020
1 parent 0007f77 commit 45a8ad7
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* Fix to not use 0.12.22 during testing which reports its version incorrectly
* Introduce tfenv-resolve-version to deduplicate translation of requested version into actual version
* README.md updates
* Fix #176 - New parameter TFENV_AUTO_INSTALL to handle the version specified by `use` or a `.terraform-version` file not being installed

## 1.0.2 (October 29, 2019)

Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,16 @@ Specify architecture. Architecture other than the default amd64 can be specified
TFENV_ARCH=arm tfenv install 0.7.9
```

##### `TFENV_AUTO_INSTALL`

String (Default: true)

Should tfenv automatically install terraform if the version specified by defaults or a .terraform-version file is not currently installed.

```console
TFENV_AUTO_INSTALL=false terraform plan
```

##### `TFENV_CURL_OUTPUT`

Integer (Default: 2)
Expand Down
9 changes: 9 additions & 0 deletions libexec/tfenv-exec
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ TFENV_VERSION="$(tfenv-version-name)" \
};
export TFENV_VERSION;

if [ ! -d "${TFENV_ROOT}/versions/${TFENV_VERSION}" ]; then
if [ "${TFENV_AUTO_INSTALL:-true}" == "true" ]; then
log 'info' "version '${TFENV_VERSION}' is not installed (set by $(tfenv-version-file)). Installing now as TFENV_AUTO_INSTALL==true";
tfenv-install;
else
log 'error' "version '${TFENV_VERSION}' was requested, but not installed and TFENV_AUTO_INSTALL is not 'true'";
fi;
fi;

TF_BIN_PATH="${TFENV_ROOT}/versions/${TFENV_VERSION}/terraform";
export PATH="${TF_BIN_PATH}:${PATH}";
log 'debug' "TF_BIN_PATH added to PATH: ${TF_BIN_PATH}";
Expand Down
9 changes: 5 additions & 4 deletions libexec/tfenv-version-name
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,9 @@ fi;
[ -z "${TFENV_VERSION}" ] \
&& log 'error' "Version could not be resolved (set by ${TFENV_VERSION_FILE} or tfenv use <version>)";

if [ -d "${TFENV_ROOT}/versions/${TFENV_VERSION}" ]; then
echo "${TFENV_VERSION}";
else
log 'warn' "version '${TFENV_VERSION}' is not installed (set by ${TFENV_VERSION_FILE})";
if [ ! -d "${TFENV_ROOT}/versions/${TFENV_VERSION}" ]; then
log 'debug' "version '${TFENV_VERSION}' is not installed (set by ${TFENV_VERSION_FILE})";
fi;

echo "${TFENV_VERSION}";

0 comments on commit 45a8ad7

Please sign in to comment.