Skip to content

Commit

Permalink
fix: Update error messages when working with OpenTofu (#4996)
Browse files Browse the repository at this point in the history
  • Loading branch information
meringu authored Oct 10, 2024
1 parent c13a42d commit 110ef94
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions server/core/terraform/terraform_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func NewClientWithDefaultVersion(
return nil, fmt.Errorf("%s not found in $PATH. Set --%s or download terraform from https://developer.hashicorp.com/terraform/downloads", distribution.BinName(), defaultVersionFlagName)
}
if err == nil {
localVersion, err = getVersion(localPath)
localVersion, err = getVersion(localPath, distribution.BinName())
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -529,7 +529,7 @@ func ensureVersion(
execPath, err := dist.Downloader().Install(context.Background(), binDir, downloadURL, v)

if err != nil {
return "", errors.Wrapf(err, "error downloading terraform version %s", v.String())
return "", errors.Wrapf(err, "error downloading %s version %s", dist.BinName(), v.String())
}

log.Info("Downloaded %s %s to %s", dist.BinName(), v.String(), execPath)
Expand Down Expand Up @@ -576,15 +576,15 @@ func isAsyncEligibleCommand(cmd string) bool {
return false
}

func getVersion(tfBinary string) (*version.Version, error) {
func getVersion(tfBinary string, binName string) (*version.Version, error) {
versionOutBytes, err := exec.Command(tfBinary, "version").Output() // #nosec
versionOutput := string(versionOutBytes)
if err != nil {
return nil, errors.Wrapf(err, "running terraform version: %s", versionOutput)
return nil, errors.Wrapf(err, "running %s version: %s", binName, versionOutput)
}
match := versionRegex.FindStringSubmatch(versionOutput)
if len(match) <= 1 {
return nil, fmt.Errorf("could not parse terraform version from %s", versionOutput)
return nil, fmt.Errorf("could not parse %s version from %s", binName, versionOutput)
}
return version.NewVersion(match[1])
}
Expand Down

0 comments on commit 110ef94

Please sign in to comment.