Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Commit 0a596d2

Browse files
command/version: Report the current platform
Along with all of the other information we previously reported in the "terraform version" output, we'll now include the name of the current platform as our provider mechanisms represent it. This is addressing a long-standing minor annoyance where we often can't tell from an incomplete bug report which platform Terraform was running on, and incomplete bug reporters do tend to at least include the "terraform version" output even if they don't also include the requested full trace log. However, what motivated doing it _now_ is that anyone building a provider registry or mirror needs to have some awareness of these platform identifiers which have been, until v0.13, mostly an implementation detail. This additional information is a small thing we can do to help registry builders find out what the platform identifier ought to be for each of the platforms they aim to support, even if some of them are platforms which the Go compiler allows but which HashiCorp doesn't officially support. The new information is on a line of its own in the output as a pragmatic way to avoid breaking anyone who might be using something like $(terraform version | head -n1) to print a brief Terraform version identifier into some logs. That's not an interface we officially support for machine consumption, but it's easy to avoid breaking it here and so we won't do so.
1 parent 24d6c74 commit 0a596d2

3 files changed

Lines changed: 21 additions & 6 deletions

File tree

command/version.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
"github.com/hashicorp/terraform/addrs"
1111
"github.com/hashicorp/terraform/internal/depsfile"
12+
"github.com/hashicorp/terraform/internal/getproviders"
1213
)
1314

1415
// VersionCommand is a Command implementation prints the version.
@@ -19,11 +20,13 @@ type VersionCommand struct {
1920
Version string
2021
VersionPrerelease string
2122
CheckFunc VersionCheckFunc
23+
Platform getproviders.Platform
2224
}
2325

2426
type VersionOutput struct {
2527
Version string `json:"terraform_version"`
2628
Revision string `json:"terraform_revision"`
29+
Platform string `json:"platform"`
2730
ProviderSelections map[string]string `json:"provider_selections"`
2831
Outdated bool `json:"terraform_outdated"`
2932
}
@@ -137,6 +140,7 @@ func (c *VersionCommand) Run(args []string) int {
137140
output := VersionOutput{
138141
Version: versionOutput,
139142
Revision: c.Revision,
143+
Platform: c.Platform.String(),
140144
ProviderSelections: selectionsOutput,
141145
Outdated: outdated,
142146
}
@@ -150,6 +154,8 @@ func (c *VersionCommand) Run(args []string) int {
150154
return 0
151155
} else {
152156
c.Ui.Output(versionString.String())
157+
c.Ui.Output(fmt.Sprintf("on %s", c.Platform))
158+
153159
if len(providerVersions) != 0 {
154160
sort.Strings(providerVersions)
155161
for _, str := range providerVersions {

command/version_test.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ func TestVersion(t *testing.T) {
4949
},
5050
Version: "4.5.6",
5151
VersionPrerelease: "foo",
52+
Platform: getproviders.Platform{OS: "aros", Arch: "riscv64"},
5253
}
5354
if err := c.replaceLockedDependencies(locks); err != nil {
5455
t.Fatal(err)
@@ -58,7 +59,7 @@ func TestVersion(t *testing.T) {
5859
}
5960

6061
actual := strings.TrimSpace(ui.OutputWriter.String())
61-
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"
62+
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"
6263
if actual != expected {
6364
t.Fatalf("wrong output\ngot:\n%s\nwant:\n%s", actual, expected)
6465
}
@@ -76,14 +77,15 @@ func TestVersion_flags(t *testing.T) {
7677
Meta: m,
7778
Version: "4.5.6",
7879
VersionPrerelease: "foo",
80+
Platform: getproviders.Platform{OS: "aros", Arch: "riscv64"},
7981
}
8082

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

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

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

108111
actual := strings.TrimSpace(ui.OutputWriter.String())
109-
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"
112+
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"
110113
if actual != expected {
111114
t.Fatalf("wrong output\ngot: %#v\nwant: %#v", actual, expected)
112115
}
@@ -127,8 +130,9 @@ func TestVersion_json(t *testing.T) {
127130

128131
// `terraform version -json` without prerelease
129132
c := &VersionCommand{
130-
Meta: meta,
131-
Version: "4.5.6",
133+
Meta: meta,
134+
Version: "4.5.6",
135+
Platform: getproviders.Platform{OS: "aros", Arch: "riscv64"},
132136
}
133137
if code := c.Run([]string{"-json"}); code != 0 {
134138
t.Fatalf("bad: \n%s", ui.ErrorWriter.String())
@@ -139,6 +143,7 @@ func TestVersion_json(t *testing.T) {
139143
{
140144
"terraform_version": "4.5.6",
141145
"terraform_revision": "",
146+
"platform": "aros_riscv64",
142147
"provider_selections": {},
143148
"terraform_outdated": false
144149
}
@@ -172,6 +177,7 @@ func TestVersion_json(t *testing.T) {
172177
Meta: meta,
173178
Version: "4.5.6",
174179
VersionPrerelease: "foo",
180+
Platform: getproviders.Platform{OS: "aros", Arch: "riscv64"},
175181
}
176182
if err := c.replaceLockedDependencies(locks); err != nil {
177183
t.Fatal(err)
@@ -185,6 +191,7 @@ func TestVersion_json(t *testing.T) {
185191
{
186192
"terraform_version": "4.5.6-foo",
187193
"terraform_revision": "",
194+
"platform": "aros_riscv64",
188195
"provider_selections": {
189196
"registry.terraform.io/hashicorp/test1": "7.8.9-beta.2",
190197
"registry.terraform.io/hashicorp/test2": "1.2.3"
@@ -208,14 +215,15 @@ func TestVersion_jsonoutdated(t *testing.T) {
208215
Meta: m,
209216
Version: "4.5.6",
210217
CheckFunc: mockVersionCheckFunc(true, "4.5.7"),
218+
Platform: getproviders.Platform{OS: "aros", Arch: "riscv64"},
211219
}
212220

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

217225
actual := strings.TrimSpace(ui.OutputWriter.String())
218-
expected := "{\n \"terraform_version\": \"4.5.6\",\n \"terraform_revision\": \"\",\n \"provider_selections\": {},\n \"terraform_outdated\": true\n}"
226+
expected := "{\n \"terraform_version\": \"4.5.6\",\n \"terraform_revision\": \"\",\n \"platform\": \"aros_riscv64\",\n \"provider_selections\": {},\n \"terraform_outdated\": true\n}"
219227
if actual != expected {
220228
t.Fatalf("wrong output\ngot: %#v\nwant: %#v", actual, expected)
221229
}

commands.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ func initCommands(
284284
Revision: GitCommit,
285285
Version: Version,
286286
VersionPrerelease: VersionPrerelease,
287+
Platform: getproviders.CurrentPlatform,
287288
CheckFunc: commandVersionCheck,
288289
}, nil
289290
},

0 commit comments

Comments
 (0)