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.
This commit is contained in:
Pam Selle 2021-01-12 16:35:30 -05:00
parent ae52190c01
commit 83e6703bf7
7 changed files with 3 additions and 24 deletions

1
.tfdev
View File

@ -1,5 +1,4 @@
version_info { version_info {
commit_var = "main.GitCommit"
version_var = "github.com/hashicorp/terraform/version.Version" version_var = "github.com/hashicorp/terraform/version.Version"
prerelease_var = "github.com/hashicorp/terraform/version.Prerelease" prerelease_var = "github.com/hashicorp/terraform/version.Prerelease"
} }

View File

@ -16,7 +16,6 @@ import (
type VersionCommand struct { type VersionCommand struct {
Meta Meta
Revision string
Version string Version string
VersionPrerelease string VersionPrerelease string
CheckFunc VersionCheckFunc CheckFunc VersionCheckFunc
@ -25,7 +24,6 @@ type VersionCommand struct {
type VersionOutput struct { type VersionOutput struct {
Version string `json:"terraform_version"` Version string `json:"terraform_version"`
Revision string `json:"terraform_revision"`
Platform string `json:"platform"` Platform string `json:"platform"`
ProviderSelections map[string]string `json:"provider_selections"` ProviderSelections map[string]string `json:"provider_selections"`
Outdated bool `json:"terraform_outdated"` Outdated bool `json:"terraform_outdated"`
@ -80,10 +78,6 @@ func (c *VersionCommand) Run(args []string) int {
fmt.Fprintf(&versionString, "Terraform v%s", c.Version) fmt.Fprintf(&versionString, "Terraform v%s", c.Version)
if c.VersionPrerelease != "" { if c.VersionPrerelease != "" {
fmt.Fprintf(&versionString, "-%s", c.VersionPrerelease) fmt.Fprintf(&versionString, "-%s", c.VersionPrerelease)
if c.Revision != "" {
fmt.Fprintf(&versionString, " (%s)", c.Revision)
}
} }
// We'll also attempt to print out the selected plugin versions. We do // We'll also attempt to print out the selected plugin versions. We do
@ -139,7 +133,6 @@ func (c *VersionCommand) Run(args []string) int {
output := VersionOutput{ output := VersionOutput{
Version: versionOutput, Version: versionOutput,
Revision: c.Revision,
Platform: c.Platform.String(), Platform: c.Platform.String(),
ProviderSelections: selectionsOutput, ProviderSelections: selectionsOutput,
Outdated: outdated, Outdated: outdated,

View File

@ -142,7 +142,6 @@ func TestVersion_json(t *testing.T) {
expected := strings.TrimSpace(` expected := strings.TrimSpace(`
{ {
"terraform_version": "4.5.6", "terraform_version": "4.5.6",
"terraform_revision": "",
"platform": "aros_riscv64", "platform": "aros_riscv64",
"provider_selections": {}, "provider_selections": {},
"terraform_outdated": false "terraform_outdated": false
@ -190,7 +189,6 @@ func TestVersion_json(t *testing.T) {
expected = strings.TrimSpace(` expected = strings.TrimSpace(`
{ {
"terraform_version": "4.5.6-foo", "terraform_version": "4.5.6-foo",
"terraform_revision": "",
"platform": "aros_riscv64", "platform": "aros_riscv64",
"provider_selections": { "provider_selections": {
"registry.terraform.io/hashicorp/test1": "7.8.9-beta.2", "registry.terraform.io/hashicorp/test1": "7.8.9-beta.2",
@ -223,7 +221,7 @@ func TestVersion_jsonoutdated(t *testing.T) {
} }
actual := strings.TrimSpace(ui.OutputWriter.String()) actual := strings.TrimSpace(ui.OutputWriter.String())
expected := "{\n \"terraform_version\": \"4.5.6\",\n \"terraform_revision\": \"\",\n \"platform\": \"aros_riscv64\",\n \"provider_selections\": {},\n \"terraform_outdated\": true\n}" expected := "{\n \"terraform_version\": \"4.5.6\",\n \"platform\": \"aros_riscv64\",\n \"provider_selections\": {},\n \"terraform_outdated\": true\n}"
if actual != expected { if actual != expected {
t.Fatalf("wrong output\ngot: %#v\nwant: %#v", actual, expected) t.Fatalf("wrong output\ngot: %#v\nwant: %#v", actual, expected)
} }

View File

@ -270,7 +270,6 @@ func initCommands(
"version": func() (cli.Command, error) { "version": func() (cli.Command, error) {
return &command.VersionCommand{ return &command.VersionCommand{
Meta: meta, Meta: meta,
Revision: GitCommit,
Version: Version, Version: Version,
VersionPrerelease: VersionPrerelease, VersionPrerelease: VersionPrerelease,
Platform: getproviders.CurrentPlatform, Platform: getproviders.CurrentPlatform,

View File

@ -117,8 +117,8 @@ func wrappedMain() int {
} }
log.Printf( log.Printf(
"[INFO] Terraform version: %s %s %s", "[INFO] Terraform version: %s %s",
Version, VersionPrerelease, GitCommit) Version, VersionPrerelease)
log.Printf("[INFO] Go runtime version: %s", runtime.Version()) log.Printf("[INFO] Go runtime version: %s", runtime.Version())
log.Printf("[INFO] CLI args: %#v", os.Args) log.Printf("[INFO] CLI args: %#v", os.Args)

View File

@ -10,10 +10,6 @@ DIR="$( cd -P "$( dirname "$SOURCE" )/.." && pwd )"
# Change into that directory # Change into that directory
cd "$DIR" cd "$DIR"
# Get the git commit
GIT_COMMIT=$(git rev-parse HEAD)
GIT_DIRTY=$(test -n "`git status --porcelain`" && echo "+CHANGES" || true)
# Determine the arch/os combos we're building for # Determine the arch/os combos we're building for
XC_ARCH=${XC_ARCH:-"386 amd64 arm"} XC_ARCH=${XC_ARCH:-"386 amd64 arm"}
XC_OS=${XC_OS:-linux darwin windows freebsd openbsd solaris} XC_OS=${XC_OS:-linux darwin windows freebsd openbsd solaris}
@ -29,9 +25,6 @@ mkdir -p bin/
if [[ -n "${TF_DEV}" ]]; then if [[ -n "${TF_DEV}" ]]; then
XC_OS=$(go env GOOS) XC_OS=$(go env GOOS)
XC_ARCH=$(go env GOARCH) XC_ARCH=$(go env GOARCH)
# Allow LD_FLAGS to be appended during development compilations
LD_FLAGS="-X main.GitCommit=${GIT_COMMIT}${GIT_DIRTY} $LD_FLAGS"
fi fi
if ! which gox > /dev/null; then if ! which gox > /dev/null; then

View File

@ -4,9 +4,6 @@ import (
"github.com/hashicorp/terraform/version" "github.com/hashicorp/terraform/version"
) )
// The git commit that was compiled. This will be filled in by the compiler.
var GitCommit string
var Version = version.Version var Version = version.Version
var VersionPrerelease = version.Prerelease var VersionPrerelease = version.Prerelease