From 3f6a7f3ed216dca83978038e58527e0891f0eeba Mon Sep 17 00:00:00 2001 From: James Bardin Date: Thu, 19 Oct 2017 19:08:35 -0400 Subject: [PATCH] add a terraform version package Many terraform project packages now want access to the current terraform version information. Since most packages end up being consumed by the core terraform package, preventing import cycles becomes difficult. --- version/version.go | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 version/version.go diff --git a/version/version.go b/version/version.go new file mode 100644 index 0000000000..34fe18a841 --- /dev/null +++ b/version/version.go @@ -0,0 +1,36 @@ +// The version package provides a location to set the release versions for all +// packages to consume, without creating import cycles. +// +// This pckage should not import any other terraform packages. +package version + +import ( + "fmt" + + version "github.com/hashicorp/go-version" +) + +// The main version number that is being run at the moment. +const Version = "0.10.8" + +// A pre-release marker for the version. If this is "" (empty string) +// then it means that it is a final release. Otherwise, this is a pre-release +// such as "dev" (in development), "beta", "rc1", etc. +var Prerelease = "dev" + +// SemVersion is an instance of version.Version. This has the secondary +// benefit of verifying during tests and init time that our version is a +// proper semantic version, which should always be the case. +var SemVersion = version.Must(version.NewVersion(Version)) + +// Header is the header name used to send the current terraform version +// in http requests. +const Header = "Terraform-Version" + +// String returns the complete version string, including prerelease +func String() string { + if prerelase != "" { + return fmt.Sprintf("%s-%s", version, prerelease) + } + return version +}