Skip to content

Commit

Permalink
More robust Terraform version parsing (#100)
Browse files Browse the repository at this point in the history
Co-authored-by: Ubuntu <[email protected]>
  • Loading branch information
srdecny and Ubuntu authored Oct 21, 2021
1 parent 968ecfc commit d41c424
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions terraform/terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
"os"
"os/exec"
"path/filepath"
"regexp"
"strconv"
"strings"
"regexp"

"github.com/bmatcuk/doublestar"
"github.com/env0/terratag/errors"
Expand All @@ -23,8 +23,9 @@ func GetTerraformVersion() convert.Version {
outputAsString := strings.TrimSpace(string(output))
errors.PanicOnError(err, &outputAsString)

regexp.MustCompile(`Terraform v(\d+)\.(\d+)\.\d+`)
matches := strings.Split(strings.TrimPrefix(strings.TrimSpace(outputAsString), "Terraform v"), ".")
regularExpression := regexp.MustCompile(`Terraform v(\d+).(\d+)\.\d+`)
matches := regularExpression.FindStringSubmatch(outputAsString)[1:]

if matches == nil {
log.Fatalln("Unable to parse 'terraform version'")
return convert.Version{}
Expand Down

0 comments on commit d41c424

Please sign in to comment.