From b7f72a515fdc2803036f3245920379d0c5347497 Mon Sep 17 00:00:00 2001 From: Mike Peachey Date: Sun, 16 Feb 2020 16:01:01 +0000 Subject: [PATCH] Don't overwrite .terraform-version files. Only change the default. Warn when overridden --- CHANGELOG.md | 3 ++- libexec/tfenv-use | 9 ++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c0207ca..a371754 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,9 @@ -## 2.0.0-alpha1 (November 24, 2019) +## 2.0.0 (Unreleased) * New logging library * New bash4 dependency * Massive testing, logging and loading refactoring + * Fix to 'use' logic: don't overwrite .terraform-version files ## 1.0.2 (October 29, 2019) diff --git a/libexec/tfenv-use b/libexec/tfenv-use index b07dcca..d701f28 100755 --- a/libexec/tfenv-use +++ b/libexec/tfenv-use @@ -108,13 +108,16 @@ target_path="${TFENV_ROOT}/versions/${version}"; [ -x "${target_path}/terraform" ] \ || log 'error' "Version directory for ${version} is present, but the terraform binary is not executable! Manual intervention required."; -log 'info' "Switching to v${version}"; - -version_file="$(tfenv-version-file)"; +log 'info' "Switching default version to v${version}"; +version_file="${TFENV_ROOT}/version"; log 'debug' "Writing \"${version}\" to \"${version_file}\""; echo "${version}" > "${version_file}" \ || log 'error' "Switch to v${version} failed"; +if [ "${version_file}" != "$(tfenv-version-file)" ]; then + log 'warn' "Default version file overridden by $(tfenv-version-file), changing the default version has no effect"; +fi; + terraform --version 1>/dev/null \ || log 'error' "'terraform --version' failed. Something is seriously wrong"; log 'info' "Switching completed";