Skip to content

Commit 83e6703

Browse files
committed
Remove revision from version command
The revision field is only populated on dev builds so this means most releases of Terraform have an empty "terraform_revision" field in the JSON output. Since we recommend developers use go tooling to `go build` this tool when developing, the revision is not useful data and so it is removed.
1 parent ae52190 commit 83e6703

File tree

7 files changed

+3
-24
lines changed

7 files changed

+3
-24
lines changed

.tfdev

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
version_info {
2-
commit_var = "main.GitCommit"
32
version_var = "github.com/hashicorp/terraform/version.Version"
43
prerelease_var = "github.com/hashicorp/terraform/version.Prerelease"
54
}

command/version.go

-7
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
type VersionCommand struct {
1717
Meta
1818

19-
Revision string
2019
Version string
2120
VersionPrerelease string
2221
CheckFunc VersionCheckFunc
@@ -25,7 +24,6 @@ type VersionCommand struct {
2524

2625
type VersionOutput struct {
2726
Version string `json:"terraform_version"`
28-
Revision string `json:"terraform_revision"`
2927
Platform string `json:"platform"`
3028
ProviderSelections map[string]string `json:"provider_selections"`
3129
Outdated bool `json:"terraform_outdated"`
@@ -80,10 +78,6 @@ func (c *VersionCommand) Run(args []string) int {
8078
fmt.Fprintf(&versionString, "Terraform v%s", c.Version)
8179
if c.VersionPrerelease != "" {
8280
fmt.Fprintf(&versionString, "-%s", c.VersionPrerelease)
83-
84-
if c.Revision != "" {
85-
fmt.Fprintf(&versionString, " (%s)", c.Revision)
86-
}
8781
}
8882

8983
// We'll also attempt to print out the selected plugin versions. We do
@@ -139,7 +133,6 @@ func (c *VersionCommand) Run(args []string) int {
139133

140134
output := VersionOutput{
141135
Version: versionOutput,
142-
Revision: c.Revision,
143136
Platform: c.Platform.String(),
144137
ProviderSelections: selectionsOutput,
145138
Outdated: outdated,

command/version_test.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ func TestVersion_json(t *testing.T) {
142142
expected := strings.TrimSpace(`
143143
{
144144
"terraform_version": "4.5.6",
145-
"terraform_revision": "",
146145
"platform": "aros_riscv64",
147146
"provider_selections": {},
148147
"terraform_outdated": false
@@ -190,7 +189,6 @@ func TestVersion_json(t *testing.T) {
190189
expected = strings.TrimSpace(`
191190
{
192191
"terraform_version": "4.5.6-foo",
193-
"terraform_revision": "",
194192
"platform": "aros_riscv64",
195193
"provider_selections": {
196194
"registry.terraform.io/hashicorp/test1": "7.8.9-beta.2",
@@ -223,7 +221,7 @@ func TestVersion_jsonoutdated(t *testing.T) {
223221
}
224222

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

commands.go

-1
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,6 @@ func initCommands(
270270
"version": func() (cli.Command, error) {
271271
return &command.VersionCommand{
272272
Meta: meta,
273-
Revision: GitCommit,
274273
Version: Version,
275274
VersionPrerelease: VersionPrerelease,
276275
Platform: getproviders.CurrentPlatform,

main.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ func wrappedMain() int {
117117
}
118118

119119
log.Printf(
120-
"[INFO] Terraform version: %s %s %s",
121-
Version, VersionPrerelease, GitCommit)
120+
"[INFO] Terraform version: %s %s",
121+
Version, VersionPrerelease)
122122
log.Printf("[INFO] Go runtime version: %s", runtime.Version())
123123
log.Printf("[INFO] CLI args: %#v", os.Args)
124124

scripts/build.sh

-7
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ DIR="$( cd -P "$( dirname "$SOURCE" )/.." && pwd )"
1010
# Change into that directory
1111
cd "$DIR"
1212

13-
# Get the git commit
14-
GIT_COMMIT=$(git rev-parse HEAD)
15-
GIT_DIRTY=$(test -n "`git status --porcelain`" && echo "+CHANGES" || true)
16-
1713
# Determine the arch/os combos we're building for
1814
XC_ARCH=${XC_ARCH:-"386 amd64 arm"}
1915
XC_OS=${XC_OS:-linux darwin windows freebsd openbsd solaris}
@@ -29,9 +25,6 @@ mkdir -p bin/
2925
if [[ -n "${TF_DEV}" ]]; then
3026
XC_OS=$(go env GOOS)
3127
XC_ARCH=$(go env GOARCH)
32-
33-
# Allow LD_FLAGS to be appended during development compilations
34-
LD_FLAGS="-X main.GitCommit=${GIT_COMMIT}${GIT_DIRTY} $LD_FLAGS"
3528
fi
3629

3730
if ! which gox > /dev/null; then

version.go

-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ import (
44
"github.com/hashicorp/terraform/version"
55
)
66

7-
// The git commit that was compiled. This will be filled in by the compiler.
8-
var GitCommit string
9-
107
var Version = version.Version
118

129
var VersionPrerelease = version.Prerelease

0 commit comments

Comments
 (0)