From 0885784b9e72bf2c7aa6f71f07132b33d8486282 Mon Sep 17 00:00:00 2001 From: Katy Moe Date: Tue, 11 Aug 2020 23:42:35 +0100 Subject: [PATCH] tolerate reversed version output --- tfexec/version.go | 4 ++-- tfinstall/tfinstall.go | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tfexec/version.go b/tfexec/version.go index be7d9b9b..79f11f59 100644 --- a/tfexec/version.go +++ b/tfexec/version.go @@ -63,7 +63,7 @@ func (tf *Terraform) version(ctx context.Context) (*version.Version, map[string] var ( simpleVersionRe = `v?(?P[0-9]+(?:\.[0-9]+)*(?:-[A-Za-z0-9\.]+)?)` - versionOutputRe = regexp.MustCompile(`^Terraform ` + simpleVersionRe) + versionOutputRe = regexp.MustCompile(`Terraform ` + simpleVersionRe) providerVersionOutputRe = regexp.MustCompile(`(\n\+ provider[\. ](?P\S+) ` + simpleVersionRe + `)`) ) @@ -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]) diff --git a/tfinstall/tfinstall.go b/tfinstall/tfinstall.go index 0330f03b..c343abe6 100644 --- a/tfinstall/tfinstall.go +++ b/tfinstall/tfinstall.go @@ -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) }