Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tolerate reversed version output #47

Merged
merged 1 commit into from
Aug 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tfexec/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (tf *Terraform) version(ctx context.Context) (*version.Version, map[string]
var (
simpleVersionRe = `v?(?P<version>[0-9]+(?:\.[0-9]+)*(?:-[A-Za-z0-9\.]+)?)`

versionOutputRe = regexp.MustCompile(`^Terraform ` + simpleVersionRe)
versionOutputRe = regexp.MustCompile(`Terraform ` + simpleVersionRe)
providerVersionOutputRe = regexp.MustCompile(`(\n\+ provider[\. ](?P<name>\S+) ` + simpleVersionRe + `)`)
)

Expand All @@ -84,7 +84,7 @@ func parseVersionOutput(stdout string) (*version.Version, map[string]*version.Ve

for _, submatches := range allSubmatches {
if len(submatches) != 4 {
return nil, nil, fmt.Errorf("unexpected number of providerion version matches %d for %s", len(submatches), stdout)
return nil, nil, fmt.Errorf("unexpected number of provider version matches %d for %s", len(submatches), stdout)
}

v, err := version.NewVersion(submatches[3])
Expand Down
3 changes: 2 additions & 1 deletion tfinstall/tfinstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,8 @@ func runTerraformVersion(execPath string) error {
return err
}

if !strings.HasPrefix(string(out), "Terraform v") {
// very basic sanity check
if !strings.Contains(string(out), "Terraform v") {
return fmt.Errorf("located executable at %s, but output of `terraform version` was:\n%s", execPath, out)
}

Expand Down