Skip to content

Commit

Permalink
Merge branch 'master' into download-latest-version-if-regex-is-used
Browse files Browse the repository at this point in the history
  • Loading branch information
Zordrak authored Aug 14, 2021
2 parents 131e25c + 3769e99 commit ee39309
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 21 deletions.
8 changes: 8 additions & 0 deletions libexec/tfenv-min-required
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ find_min_required() {
else
found_min_required="$(echo "$found_min_required")";
#echo "Min required version is detected as ${found_min_required}";

# Probably not an advisable way to choose a terraform version,
# but this is the way this functionality works in terraform:
# add .0 to versions without a minor and/or patch version (e.g. 12.0)
while ! [[ "${found_min_required}" =~ [0-9]+\.[0-9]+\.[0-9]+ ]]; do
found_min_required="${found_min_required}.0";
done;

echo "${found_min_required}";
exit 0;
fi;
Expand Down
54 changes: 33 additions & 21 deletions test/test_use_minrequired.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,44 +50,56 @@ fi;

declare -a errors=();

log 'info' '### Install not min-required version';
cleanup || log 'error' 'Cleanup failed?!';

v='0.8.8';
minv='0.8.0';
minv_tag='0.13.0-rc1'
(
tfenv install "${v}" || true;
tfenv use "${v}" || exit 1;
check_active_version "${v}" || exit 1;
) || error_and_proceed "Installing specific version ${v}";


log 'info' '### Install min-required normal version (#.#.#)';

echo "terraform {
minv='0.8.0';

echo "terraform {
required_version = \">=${minv}\"
}" >> min_required.tf;

tfenv install min-required;
tfenv use min-required;
}" > min_required.tf;

check_active_version "${minv}" || error_and_proceed 'Min required version does not match';
(
tfenv install min-required;
tfenv use min-required;
check_active_version "${minv}";
) || error_and_proceed 'Min required version does not match';

cleanup || log 'error' 'Cleanup failed?!';


log 'info' '### Install min-required tagged version (#.#.#-tag#)'

minv='0.13.0-rc1'

echo "terraform {
required_version = \">=${minv}\"
}" > min_required.tf;

required_version = \">=${minv_tag}\"
}" >> min_required.tf;
(
tfenv install min-required;
tfenv use min-required;
check_active_version "${minv}";
) || error_and_proceed 'Min required tagged-version does not match';

cleanup || log 'error' 'Cleanup failed?!';


log 'info' '### Install min-required incomplete version (#.#.<missing>)'

tfenv install min-required
tfenv use min-required
minv='0.12';

check_active_version "${minv_tag}" || error_and_proceed 'Min required version does not match';
echo "terraform {
required_version = \">=${minv}\"
}" >> min_required.tf;

(
tfenv install min-required;
tfenv use min-required;
check_active_version "${minv}.0";
) || error_and_proceed 'Min required incomplete-version does not match';

cleanup || log 'error' 'Cleanup failed?!';

Expand Down

0 comments on commit ee39309

Please sign in to comment.