Skip to content

Commit 45a8ad7

Browse files
committed
Fix the failure to correctly handle a version requested not being installed. Handle it with the defaulted option to automatically install missing versions
1 parent 0007f77 commit 45a8ad7

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* Fix to not use 0.12.22 during testing which reports its version incorrectly
88
* Introduce tfenv-resolve-version to deduplicate translation of requested version into actual version
99
* README.md updates
10+
* Fix #176 - New parameter TFENV_AUTO_INSTALL to handle the version specified by `use` or a `.terraform-version` file not being installed
1011

1112
## 1.0.2 (October 29, 2019)
1213

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,16 @@ Specify architecture. Architecture other than the default amd64 can be specified
138138
TFENV_ARCH=arm tfenv install 0.7.9
139139
```
140140

141+
##### `TFENV_AUTO_INSTALL`
142+
143+
String (Default: true)
144+
145+
Should tfenv automatically install terraform if the version specified by defaults or a .terraform-version file is not currently installed.
146+
147+
```console
148+
TFENV_AUTO_INSTALL=false terraform plan
149+
```
150+
141151
##### `TFENV_CURL_OUTPUT`
142152

143153
Integer (Default: 2)

libexec/tfenv-exec

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,15 @@ TFENV_VERSION="$(tfenv-version-name)" \
8383
};
8484
export TFENV_VERSION;
8585

86+
if [ ! -d "${TFENV_ROOT}/versions/${TFENV_VERSION}" ]; then
87+
if [ "${TFENV_AUTO_INSTALL:-true}" == "true" ]; then
88+
log 'info' "version '${TFENV_VERSION}' is not installed (set by $(tfenv-version-file)). Installing now as TFENV_AUTO_INSTALL==true";
89+
tfenv-install;
90+
else
91+
log 'error' "version '${TFENV_VERSION}' was requested, but not installed and TFENV_AUTO_INSTALL is not 'true'";
92+
fi;
93+
fi;
94+
8695
TF_BIN_PATH="${TFENV_ROOT}/versions/${TFENV_VERSION}/terraform";
8796
export PATH="${TF_BIN_PATH}:${PATH}";
8897
log 'debug' "TF_BIN_PATH added to PATH: ${TF_BIN_PATH}";

libexec/tfenv-version-name

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,9 @@ fi;
100100
[ -z "${TFENV_VERSION}" ] \
101101
&& log 'error' "Version could not be resolved (set by ${TFENV_VERSION_FILE} or tfenv use <version>)";
102102

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

0 commit comments

Comments
 (0)