|
|
|
@ -25,36 +25,38 @@ tfenv_list_sed(){
|
|
|
|
|
sed 's/^\*[[:space:]]*//; s/(.*//; s/[[:space:]]//g'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tfenv_setup(){
|
|
|
|
|
local version="${1:-${TERRAFORM_VERSION:-}}"
|
|
|
|
|
if [ -z "$version" ]; then
|
|
|
|
|
return 0
|
|
|
|
|
fi
|
|
|
|
|
if ! type -P tfenv &>/dev/null; then
|
|
|
|
|
return 0
|
|
|
|
|
fi
|
|
|
|
|
if ! tfenv list | tfenv_list_sed | grep -Fxq "$version"; then
|
|
|
|
|
echo "Terraform version '$version' not installed in tfenv, installing now..."
|
|
|
|
|
tfenv install "$version"
|
|
|
|
|
fi
|
|
|
|
|
local current_version
|
|
|
|
|
current_version="$(tfenv list | grep '^\*' | tfenv_list_sed)"
|
|
|
|
|
if [ "$current_version" != "$version" ]; then
|
|
|
|
|
# XXX: Careful, this will switch globally and could cause race conditions with other shells / scripts on the same machine
|
|
|
|
|
tfenv use "$version"
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tfenv_setup "$TERRAFORM_VERSION"
|
|
|
|
|
# tfenv installs automatically if TFENV_AUTO_INSTALL=true (default)
|
|
|
|
|
#tfenv_setup(){
|
|
|
|
|
# local version="${1:-${TERRAFORM_VERSION:-}}"
|
|
|
|
|
# if [ -z "$version" ]; then
|
|
|
|
|
# return 0
|
|
|
|
|
# fi
|
|
|
|
|
# if ! type -P tfenv &>/dev/null; then
|
|
|
|
|
# return 0
|
|
|
|
|
# fi
|
|
|
|
|
# if ! tfenv list | tfenv_list_sed | grep -Fxq "$version"; then
|
|
|
|
|
# echo "Terraform version '$version' not installed in tfenv, installing now..."
|
|
|
|
|
# tfenv install "$version"
|
|
|
|
|
# fi
|
|
|
|
|
# local current_version
|
|
|
|
|
# current_version="$(tfenv list | grep '^\*' | tfenv_list_sed)"
|
|
|
|
|
# if [ "$current_version" != "$version" ]; then
|
|
|
|
|
# # XXX: Careful, this will switch globally and could cause race conditions with other shells / scripts on the same machine
|
|
|
|
|
# tfenv use "$version"
|
|
|
|
|
# fi
|
|
|
|
|
#}
|
|
|
|
|
#
|
|
|
|
|
#tfenv_setup "$TERRAFORM_VERSION"
|
|
|
|
|
|
|
|
|
|
# =================================================================================
|
|
|
|
|
# for deployment/<environment> subdirectories, all you need in their .envrc is this
|
|
|
|
|
#
|
|
|
|
|
# source_up
|
|
|
|
|
#
|
|
|
|
|
# export TERRAFORM_VERSION=1.1.9
|
|
|
|
|
# export TFENV_AUTO_INSTALL=true
|
|
|
|
|
#
|
|
|
|
|
# tfenv_setup "$TERRAFORM_VERSION"
|
|
|
|
|
# #source_up
|
|
|
|
|
# # tfenv does this automatically
|
|
|
|
|
# #tfenv_setup "$TERRAFORM_VERSION"
|
|
|
|
|
#
|
|
|
|
|
# =================================================================================
|
|
|
|
|
|
|
|
|
|