Skip to content

Commit

Permalink
Remove revision from version command
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pselle committed Jan 12, 2021
1 parent ae52190 commit 83e6703
Show file tree
Hide file tree
Showing 7 changed files with 3 additions and 24 deletions.
1 change: 0 additions & 1 deletion .tfdev
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
version_info {
commit_var = "main.GitCommit"
version_var = "github.com/hashicorp/terraform/version.Version"
prerelease_var = "github.com/hashicorp/terraform/version.Prerelease"
}
Expand Down
7 changes: 0 additions & 7 deletions command/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
type VersionCommand struct {
Meta

Revision string
Version string
VersionPrerelease string
CheckFunc VersionCheckFunc
Expand All @@ -25,7 +24,6 @@ type VersionCommand struct {

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 @@ -80,10 +78,6 @@ func (c *VersionCommand) Run(args []string) int {
fmt.Fprintf(&versionString, "Terraform v%s", c.Version)
if 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
Expand Down Expand Up @@ -139,7 +133,6 @@ func (c *VersionCommand) Run(args []string) int {

output := VersionOutput{
Version: versionOutput,
Revision: c.Revision,
Platform: c.Platform.String(),
ProviderSelections: selectionsOutput,
Outdated: outdated,
Expand Down
4 changes: 1 addition & 3 deletions command/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ func TestVersion_json(t *testing.T) {
expected := strings.TrimSpace(`
{
"terraform_version": "4.5.6",
"terraform_revision": "",
"platform": "aros_riscv64",
"provider_selections": {},
"terraform_outdated": false
Expand Down Expand Up @@ -190,7 +189,6 @@ func TestVersion_json(t *testing.T) {
expected = strings.TrimSpace(`
{
"terraform_version": "4.5.6-foo",
"terraform_revision": "",
"platform": "aros_riscv64",
"provider_selections": {
"registry.terraform.io/hashicorp/test1": "7.8.9-beta.2",
Expand Down Expand Up @@ -223,7 +221,7 @@ func TestVersion_jsonoutdated(t *testing.T) {
}

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 {
t.Fatalf("wrong output\ngot: %#v\nwant: %#v", actual, expected)
}
Expand Down
1 change: 0 additions & 1 deletion commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,6 @@ func initCommands(
"version": func() (cli.Command, error) {
return &command.VersionCommand{
Meta: meta,
Revision: GitCommit,
Version: Version,
VersionPrerelease: VersionPrerelease,
Platform: getproviders.CurrentPlatform,
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ func wrappedMain() int {
}

log.Printf(
"[INFO] Terraform version: %s %s %s",
Version, VersionPrerelease, GitCommit)
"[INFO] Terraform version: %s %s",
Version, VersionPrerelease)
log.Printf("[INFO] Go runtime version: %s", runtime.Version())
log.Printf("[INFO] CLI args: %#v", os.Args)

Expand Down
7 changes: 0 additions & 7 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ DIR="$( cd -P "$( dirname "$SOURCE" )/.." && pwd )"
# Change into that directory
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
XC_ARCH=${XC_ARCH:-"386 amd64 arm"}
XC_OS=${XC_OS:-linux darwin windows freebsd openbsd solaris}
Expand All @@ -29,9 +25,6 @@ mkdir -p bin/
if [[ -n "${TF_DEV}" ]]; then
XC_OS=$(go env GOOS)
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

if ! which gox > /dev/null; then
Expand Down
3 changes: 0 additions & 3 deletions version.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ import (
"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 VersionPrerelease = version.Prerelease

0 comments on commit 83e6703

Please sign in to comment.