hashicorp / hc-install

Go module for downloading or locating HashiCorp binaries, verifying signatures and checksums, and asserting version constraints.

Home Page:https://pkg.go.dev/github.com/hashicorp/hc-install

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support Exact Path Filesystem Source

bflad opened this issue · comments

Version

v0.2.0

Use Cases

In the previous terraform-exec/tfinstall package, it was possible to perform an exact path lookup via ExactPath(). This was helpful in cases where callers may want to explicitly prefer a certain binary. For example in the Terraform Plugin SDK v2 acceptance testing framework, provider developers can set the TF_ACC_TERRAFORM_PATH environment variable (e.g. to /usr/local/bin/terraform1.1-beta1) which is selected first if present.

Alternate Solutions

Theoretically, it should be possible to os.Stat() the given exact path prior to using hc-install, but this introduces separate logic which needs to handle the automatic fallback to hc-install.

Proposal

Add an ExactPath or similar field to the fs.AnyVersion type that conflicts with ExtraPaths. This path is checked and returned if found, otherwise moving onto further sources.

Callers may need to perform base name extraction to create a custom Product so it is possible to specify binary names that do not necessarily match the baked one.

References

Another alternative might be introducing a separate filesystem source type, e.g.

// package fs
type Binary struct {
  AbsolutePath string
}