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

command/version: Report the current platform #26975

Merged
merged 2 commits into from
Nov 19, 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
6 changes: 6 additions & 0 deletions command/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/hashicorp/terraform/addrs"
"github.com/hashicorp/terraform/internal/depsfile"
"github.com/hashicorp/terraform/internal/getproviders"
)

// VersionCommand is a Command implementation prints the version.
Expand All @@ -19,11 +20,13 @@ type VersionCommand struct {
Version string
VersionPrerelease string
CheckFunc VersionCheckFunc
Platform getproviders.Platform
}

type VersionOutput struct {
Version string `json:"terraform_version"`
Revision string `json:"terraform_revision"`
Platform string `json:"platform"`
ProviderSelections map[string]string `json:"provider_selections"`
Outdated bool `json:"terraform_outdated"`
}
Expand Down Expand Up @@ -137,6 +140,7 @@ func (c *VersionCommand) Run(args []string) int {
output := VersionOutput{
Version: versionOutput,
Revision: c.Revision,
Platform: c.Platform.String(),
ProviderSelections: selectionsOutput,
Outdated: outdated,
}
Expand All @@ -150,6 +154,8 @@ func (c *VersionCommand) Run(args []string) int {
return 0
} else {
c.Ui.Output(versionString.String())
c.Ui.Output(fmt.Sprintf("on %s", c.Platform))

if len(providerVersions) != 0 {
sort.Strings(providerVersions)
for _, str := range providerVersions {
Expand Down
20 changes: 14 additions & 6 deletions command/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func TestVersion(t *testing.T) {
},
Version: "4.5.6",
VersionPrerelease: "foo",
Platform: getproviders.Platform{OS: "aros", Arch: "riscv64"},
}
if err := c.replaceLockedDependencies(locks); err != nil {
t.Fatal(err)
Expand All @@ -58,7 +59,7 @@ func TestVersion(t *testing.T) {
}

actual := strings.TrimSpace(ui.OutputWriter.String())
expected := "Terraform v4.5.6-foo\n+ provider registry.terraform.io/hashicorp/test1 v7.8.9-beta.2\n+ provider registry.terraform.io/hashicorp/test2 v1.2.3"
expected := "Terraform v4.5.6-foo\non aros_riscv64\n+ provider registry.terraform.io/hashicorp/test1 v7.8.9-beta.2\n+ provider registry.terraform.io/hashicorp/test2 v1.2.3"
if actual != expected {
t.Fatalf("wrong output\ngot:\n%s\nwant:\n%s", actual, expected)
}
Expand All @@ -76,14 +77,15 @@ func TestVersion_flags(t *testing.T) {
Meta: m,
Version: "4.5.6",
VersionPrerelease: "foo",
Platform: getproviders.Platform{OS: "aros", Arch: "riscv64"},
}

if code := c.Run([]string{"-v", "-version"}); code != 0 {
t.Fatalf("bad: \n%s", ui.ErrorWriter.String())
}

actual := strings.TrimSpace(ui.OutputWriter.String())
expected := "Terraform v4.5.6-foo"
expected := "Terraform v4.5.6-foo\non aros_riscv64"
if actual != expected {
t.Fatalf("wrong output\ngot: %#v\nwant: %#v", actual, expected)
}
Expand All @@ -99,14 +101,15 @@ func TestVersion_outdated(t *testing.T) {
Meta: m,
Version: "4.5.6",
CheckFunc: mockVersionCheckFunc(true, "4.5.7"),
Platform: getproviders.Platform{OS: "aros", Arch: "riscv64"},
}

if code := c.Run([]string{}); code != 0 {
t.Fatalf("bad: \n%s", ui.ErrorWriter.String())
}

actual := strings.TrimSpace(ui.OutputWriter.String())
expected := "Terraform v4.5.6\n\nYour version of Terraform is out of date! The latest version\nis 4.5.7. You can update by downloading from https://www.terraform.io/downloads.html"
expected := "Terraform v4.5.6\non aros_riscv64\n\nYour version of Terraform is out of date! The latest version\nis 4.5.7. You can update by downloading from https://www.terraform.io/downloads.html"
if actual != expected {
t.Fatalf("wrong output\ngot: %#v\nwant: %#v", actual, expected)
}
Expand All @@ -127,8 +130,9 @@ func TestVersion_json(t *testing.T) {

// `terraform version -json` without prerelease
c := &VersionCommand{
Meta: meta,
Version: "4.5.6",
Meta: meta,
Version: "4.5.6",
Platform: getproviders.Platform{OS: "aros", Arch: "riscv64"},
}
if code := c.Run([]string{"-json"}); code != 0 {
t.Fatalf("bad: \n%s", ui.ErrorWriter.String())
Expand All @@ -139,6 +143,7 @@ func TestVersion_json(t *testing.T) {
{
"terraform_version": "4.5.6",
"terraform_revision": "",
"platform": "aros_riscv64",
"provider_selections": {},
"terraform_outdated": false
}
Expand Down Expand Up @@ -172,6 +177,7 @@ func TestVersion_json(t *testing.T) {
Meta: meta,
Version: "4.5.6",
VersionPrerelease: "foo",
Platform: getproviders.Platform{OS: "aros", Arch: "riscv64"},
}
if err := c.replaceLockedDependencies(locks); err != nil {
t.Fatal(err)
Expand All @@ -185,6 +191,7 @@ func TestVersion_json(t *testing.T) {
{
"terraform_version": "4.5.6-foo",
"terraform_revision": "",
"platform": "aros_riscv64",
"provider_selections": {
"registry.terraform.io/hashicorp/test1": "7.8.9-beta.2",
"registry.terraform.io/hashicorp/test2": "1.2.3"
Expand All @@ -208,14 +215,15 @@ func TestVersion_jsonoutdated(t *testing.T) {
Meta: m,
Version: "4.5.6",
CheckFunc: mockVersionCheckFunc(true, "4.5.7"),
Platform: getproviders.Platform{OS: "aros", Arch: "riscv64"},
}

if code := c.Run([]string{"-json"}); code != 0 {
t.Fatalf("bad: \n%s", ui.ErrorWriter.String())
}

actual := strings.TrimSpace(ui.OutputWriter.String())
expected := "{\n \"terraform_version\": \"4.5.6\",\n \"terraform_revision\": \"\",\n \"provider_selections\": {},\n \"terraform_outdated\": true\n}"
expected := "{\n \"terraform_version\": \"4.5.6\",\n \"terraform_revision\": \"\",\n \"platform\": \"aros_riscv64\",\n \"provider_selections\": {},\n \"terraform_outdated\": true\n}"
if actual != expected {
t.Fatalf("wrong output\ngot: %#v\nwant: %#v", actual, expected)
}
Expand Down
1 change: 1 addition & 0 deletions commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ func initCommands(
Revision: GitCommit,
Version: Version,
VersionPrerelease: VersionPrerelease,
Platform: getproviders.CurrentPlatform,
CheckFunc: commandVersionCheck,
}, nil
},
Expand Down
2 changes: 1 addition & 1 deletion version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

// The main version number that is being run at the moment.
var Version = "0.14.0"
var Version = "0.15.0"

// A pre-release marker for the version. If this is "" (empty string)
// then it means that it is a final release. Otherwise, this is a pre-release
Expand Down