diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index 18e5c27ea1..ce88c85bc8 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -7,26 +7,13 @@ If we can't reproduce a bug we might close your issue. If we're wrong, PLEASE feel free to reopen it and explain why. --> -# Versions - -## Installer version: +# Version ```console $ openshift-install version ``` -## Terraform version - - - -```console -$ terraform version - -``` - # Platform (aws|libvirt|openshift): Enter text here. diff --git a/cmd/openshift-install/main.go b/cmd/openshift-install/main.go index c14d57095d..5a520d5451 100644 --- a/cmd/openshift-install/main.go +++ b/cmd/openshift-install/main.go @@ -3,6 +3,7 @@ package main import ( "fmt" "os" + "os/exec" "github.com/sirupsen/logrus" "gopkg.in/alecthomas/kingpin.v2" @@ -11,6 +12,7 @@ import ( "github.com/openshift/installer/pkg/asset/stock" "github.com/openshift/installer/pkg/destroy" _ "github.com/openshift/installer/pkg/destroy/libvirt" + "github.com/openshift/installer/pkg/terraform" ) var ( @@ -44,6 +46,15 @@ func main() { if command == versionCommand.FullCommand() { fmt.Printf("%s %s\n", os.Args[0], version) + terraformVersion, err := terraform.Version() + if err != nil { + exitError, ok := err.(*exec.ExitError) + if ok && len(exitError.Stderr) > 0 { + logrus.Error(string(exitError.Stderr)) + } + logrus.Fatalf("Failed to calculate Terraform version: %v", err) + } + fmt.Println(terraformVersion) return } diff --git a/pkg/terraform/executor.go b/pkg/terraform/executor.go index 3c526b8101..52ced7eea4 100644 --- a/pkg/terraform/executor.go +++ b/pkg/terraform/executor.go @@ -7,6 +7,7 @@ import ( "os/exec" "path/filepath" "runtime" + "strings" "github.com/sirupsen/logrus" ) @@ -73,6 +74,24 @@ func (ex *executor) execute(clusterDir string, args ...string) error { return cmd.Run() } +// Version gets the output of 'terrraform version'. +func Version() (version string, err error) { + // Find the Terraform binary. + binPath, err := tfBinaryPath() + if err != nil { + return "", err + } + + output, err := exec.Command(binPath, "version").Output() + if err != nil { + exitError := err.(*exec.ExitError) + if len(exitError.Stderr) == 0 { + exitError.Stderr = output + } + } + return strings.TrimRight(string(output), "\n"), err +} + // tfBinaryPath searches for a Terraform binary on disk: // - in the executing binary's folder, // - in the current working directory,