forked from tfutils/tfenv
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix the problems introduced with minrequired changes
- Loading branch information
Showing
11 changed files
with
94 additions
and
331 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -uo pipefail; | ||
|
||
function tfenv-min-required() { | ||
local path="${1:-.}"; | ||
|
||
local versions="$( echo $(cat ${path}/{*.tf,*.tf.json} 2>/dev/null | grep -Eh '^\s*[^#]*\s*required_version') | grep -o '[~=!<>]\{0,2\}\s*\([0-9]\+\.\?\)\{2,3\}\(-[a-z]\+[0-9]\+\)\?')"; | ||
|
||
if [[ "${versions}" =~ ([~=!<>]{0,2}[[:blank:]]*)([0-9]+[0-9.]+)[^0-9]*(-[a-z]+[0-9]+)? ]]; then | ||
qualifier="${BASH_REMATCH[1]}"; | ||
found_min_required="${BASH_REMATCH[2]}${BASH_REMATCH[3]}"; | ||
if [[ "${qualifier}" =~ ^!= ]]; then | ||
log 'debug' "required_version is a negation - we cannot guess the desired one, skipping."; | ||
else | ||
local min_required_file="$(grep -Hn required_version ${path}/{*.tf,*.tf.json} 2>/dev/null | xargs)"; | ||
|
||
# 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; | ||
|
||
log 'debug' "Determined min-required to be '${found_min_required}' (${min_required_file})"; | ||
echo -en "${found_min_required}"; | ||
return; | ||
fi; | ||
fi; | ||
|
||
log 'debug' 'Appropriate required_version not found, skipping min-required'; | ||
}; | ||
export -f tfenv-min-required; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
#!/usr/bin/env bash | ||
|
||
[ -n "${TFENV_DEBUG}" ] && set -x: | ||
[ -n "${TFENV_DEBUG}" ] && set -x; | ||
|
||
export PATH="${TFENV_ROOT}/bin:${PATH}"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.