diff --git a/command/version.go b/command/version.go index cbece20ac..f37feac06 100644 --- a/command/version.go +++ b/command/version.go @@ -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. @@ -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"` } @@ -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, } @@ -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 { diff --git a/command/version_test.go b/command/version_test.go index 3844dbd12..b0dcf892a 100644 --- a/command/version_test.go +++ b/command/version_test.go @@ -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) @@ -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) } @@ -76,6 +77,7 @@ 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 { @@ -83,7 +85,7 @@ func TestVersion_flags(t *testing.T) { } 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) } @@ -99,6 +101,7 @@ 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 { @@ -106,7 +109,7 @@ func TestVersion_outdated(t *testing.T) { } 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) } @@ -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()) @@ -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 } @@ -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) @@ -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" @@ -208,6 +215,7 @@ 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 { @@ -215,7 +223,7 @@ func TestVersion_jsonoutdated(t *testing.T) { } 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) } diff --git a/commands.go b/commands.go index dd6010ce1..1db6dfb63 100644 --- a/commands.go +++ b/commands.go @@ -284,6 +284,7 @@ func initCommands( Revision: GitCommit, Version: Version, VersionPrerelease: VersionPrerelease, + Platform: getproviders.CurrentPlatform, CheckFunc: commandVersionCheck, }, nil },