Skip to content

tfenv install min-required fails silently when working directory path contains spaces #537

Description

@PaladinZ78

Summary

tfenv install min-required (and tfenv-resolve-version with latest-allowed) fails with the error below when the current working directory contains a space in its path (e.g. ~/My Drive/project/terraform):

tfenv: [ERROR] Version is not specified. This should not be possible as we default to latest

Steps to Reproduce

  1. Place a Terraform project in a directory whose path contains a space, e.g. /Users/me/My Drive/project/terraform
  2. Add a versions.tf with required_version = ">= 1.15.5"
  3. Run tfenv install min-required

Expected Behaviour

tfenv reads required_version from the .tf files and installs the matching version.

Actual Behaviour

The error Version is not specified. This should not be possible as we default to latest is thrown and nothing is installed.

tfenv Version

3.2.2

Operating System

macOS (Intel)

OS Version

No response

Shell

zsh

Additional Context

Root cause:

In lib/tfenv-min-required.sh, the ${path} variable is unquoted in two places:

Line 6

local versions="$( echo $(cat ${path}/{.tf,.tf.json} 2>/dev/null | grep -Eh '^\s*[^#]\srequired_version') | grep -o ...)";

Line 14

local min_required_file="$(grep -Hn required_version ${path}/{.tf,.tf.json} 2>/dev/null | xargs)";

When ${path} contains a space, bash word-splits it before the brace expansion runs, breaking both cat and grep calls. No files are found, the function returns empty, and the error chain follows.

The same issue exists in libexec/tfenv-resolve-version for the latest-allowed path:

grep -h required_version "${TFENV_DIR:-$(pwd)}"/{.tf,.tf.json} 2>/dev/null

Here the variable is quoted but the brace expansion is outside the quotes, causing the same word-splitting issue.

Suggested fix:

Quote ${path} in lib/tfenv-min-required.sh:

local versions="$( echo $(cat "${path}"/{.tf,.tf.json} 2>/dev/null | grep -Eh '^\s*[^#]\srequired_version') | grep -o ...)";

local min_required_file="$(grep -Hn required_version "${path}"/{.tf,.tf.json} 2>/dev/null | xargs)";

Metadata

Metadata

Assignees

No one assigned

    Labels

    type:bugSomething is broken

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions