Commit e99563cd authored by nimrod's avatar nimrod
Browse files

Include <workspace>/*.tfvars files with tf.

The tf wrapper adds found tfvars files under a directory with the
workspace name. So you can have multiple files with nicer separation
inside a directory if you need it (also symlinks so you can keep things
DRY). I'm a little conflicted on this change because it makes the script
more complex and I like pointing out that the wrapper is just ~20 lines
of simple shell scripting. Finally, the invocation will fail with
filenames that have spaces in them.
parent 3f3b6db3
Loading
Loading
Loading
Loading
+13 −2
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@ set -eu
# the workspace name (on commands that support that).

workspace="$(terraform workspace show)"
if [ ! -f "$workspace.tfvars" ]
if [ ! -f "$workspace.tfvars" ] && [ ! -d "$workspace" ]
then
    exec terraform "$@"
fi
@@ -15,7 +15,18 @@ do
    if [ "$arg" = "plan" ] || [ "$arg" = "console" ] || [ "$arg" = "import" ] ||
        [ "$arg" = "refresh" ]
    then
        additional_args=''
        if [ -f "$workspace.tfvars" ]
        then
            additional_args="$additional_args -var-files=$workspace.tfvars"
        fi
        if [ -d "$workspace" ]
        then
            additional_args="$additional_args $(find "$workspace" -type f -name '*.tfvars' -exec printf '-var-file=%s ' {} \;)"
        fi
        exec terraform "$@" "-var-file=$workspace.tfvars"
    fi
done
exec terraform "$@"

# shellcheck disable=SC2086
exec terraform "$@" $additional_args