Summary
Implement the tfenv pin command for the Go edition — writing a .terraform-version file in the current directory.
Parent Epic
Part of #488 — Go Edition: Full Feature Parity Implementation
Motivation
tfenv pin provides a convenient way to create a .terraform-version file in the current directory, pinning the project to the currently active Terraform version. This is a simple but useful workflow command.
Clean-Room Constraint
This is a clean-room implementation. Contributors MUST NOT read, reference, copy, or adapt source code from tofuutils/tenv, hashicorp/hc-install, or any other third-party tfenv-like tool. The sole reference is tfenv's own Bash source code, documentation, and test suite.
Proposed Design
Command Interface
Pin Flow
- Validate: no arguments accepted —
tfenv pin takes no args (error if any given)
- Validate:
${TFENV_CONFIG_DIR}/versions/ directory must exist and be accessible
- Resolve the currently active version via
tfenv-version-name (version-name resolution chain)
- Write that version string to
.terraform-version in the current working directory
- Print confirmation:
Pinned version by writing "${version}" to ${PWD}/.terraform-version
Output Format
The .terraform-version file contains the version string followed by a newline:
This is produced by echo "${version_name}" > .terraform-version in Bash, which appends a newline.
Error Cases
- Arguments given →
usage: tfenv pin error, exit non-zero
- No versions directory →
No versions available. Please install one with: tfenv install
- Versions directory inaccessible →
tfenv versions directory is inaccessible: ${path}
- No version resolvable → error from version-name resolution (no version file, no default)
Acceptance Criteria
Dependencies
Implementation Notes
- Reference
libexec/tfenv-pin — only ~20 lines of logic after standalone boilerplate
- Key Bash behaviours to match:
- Line 65: No arguments accepted
- Lines 67-68: Versions directory must exist
- Lines 70-71: Versions directory must be accessible
- Lines 73-74: Resolve version via
tfenv-version-name
- Line 76: Write to
.terraform-version in current directory
- Line 77: Confirmation message with version and path
- This is one of the simplest commands — implementation should be straightforward
- Ensure the written file matches the Bash edition's format exactly (for cross-edition compatibility)
- The version resolved by
tfenv-version-name may be a keyword like latest if that's what the version file says — pin writes the RESOLVED concrete version, not the keyword
Labels
type:feature, priority:high, complexity:trivial
Summary
Implement the
tfenv pincommand for the Go edition — writing a.terraform-versionfile in the current directory.Parent Epic
Part of #488 — Go Edition: Full Feature Parity Implementation
Motivation
tfenv pinprovides a convenient way to create a.terraform-versionfile in the current directory, pinning the project to the currently active Terraform version. This is a simple but useful workflow command.Clean-Room Constraint
This is a clean-room implementation. Contributors MUST NOT read, reference, copy, or adapt source code from
tofuutils/tenv,hashicorp/hc-install, or any other third-party tfenv-like tool. The sole reference is tfenv's own Bash source code, documentation, and test suite.Proposed Design
Command Interface
Pin Flow
tfenv pintakes no args (error if any given)${TFENV_CONFIG_DIR}/versions/directory must exist and be accessibletfenv-version-name(version-name resolution chain).terraform-versionin the current working directoryPinned version by writing "${version}" to ${PWD}/.terraform-versionOutput Format
The
.terraform-versionfile contains the version string followed by a newline:This is produced by
echo "${version_name}" > .terraform-versionin Bash, which appends a newline.Error Cases
usage: tfenv pinerror, exit non-zeroNo versions available. Please install one with: tfenv installtfenv versions directory is inaccessible: ${path}Acceptance Criteria
tfenv pincreates.terraform-versionin the current directorytfenv pinwith arguments prints usage error and exits non-zeroversions/directory missing).terraform-versionif presentDependencies
Implementation Notes
libexec/tfenv-pin— only ~20 lines of logic after standalone boilerplatetfenv-version-name.terraform-versionin current directorytfenv-version-namemay be a keyword likelatestif that's what the version file says —pinwrites the RESOLVED concrete version, not the keywordLabels
type:feature,priority:high,complexity:trivial