Merge pull request #16406 from hashicorp/jbardin/version-package
Add a standalone version package for all of terraform
This commit is contained in:
commit
47c45788bc
|
@ -12,7 +12,7 @@ import (
|
||||||
"github.com/hashicorp/atlas-go/v1"
|
"github.com/hashicorp/atlas-go/v1"
|
||||||
"github.com/hashicorp/terraform/backend"
|
"github.com/hashicorp/terraform/backend"
|
||||||
"github.com/hashicorp/terraform/config"
|
"github.com/hashicorp/terraform/config"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
type PushCommand struct {
|
type PushCommand struct {
|
||||||
|
@ -174,7 +174,7 @@ func (c *PushCommand) Run(args []string) int {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
client.DefaultHeader.Set(terraform.VersionHeader, terraform.Version)
|
client.DefaultHeader.Set(version.Header, version.Version)
|
||||||
|
|
||||||
if atlasToken != "" {
|
if atlasToken != "" {
|
||||||
client.Token = atlasToken
|
client.Token = atlasToken
|
||||||
|
|
|
@ -12,6 +12,7 @@ import (
|
||||||
"github.com/hashicorp/terraform/helper/copy"
|
"github.com/hashicorp/terraform/helper/copy"
|
||||||
"github.com/hashicorp/terraform/state"
|
"github.com/hashicorp/terraform/state"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
|
"github.com/hashicorp/terraform/version"
|
||||||
"github.com/mitchellh/cli"
|
"github.com/mitchellh/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -353,7 +354,7 @@ func TestRefresh_pastState(t *testing.T) {
|
||||||
t.Fatalf("bad:\n\n%s", actual)
|
t.Fatalf("bad:\n\n%s", actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
if newState.TFVersion != terraform.Version {
|
if newState.TFVersion != version.Version {
|
||||||
t.Fatalf("bad:\n\n%s", newState.TFVersion)
|
t.Fatalf("bad:\n\n%s", newState.TFVersion)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,13 +12,14 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/pathorcontents"
|
"github.com/hashicorp/terraform/helper/pathorcontents"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
"golang.org/x/oauth2/google"
|
"golang.org/x/oauth2/google"
|
||||||
"golang.org/x/oauth2/jwt"
|
"golang.org/x/oauth2/jwt"
|
||||||
"google.golang.org/api/googleapi"
|
"google.golang.org/api/googleapi"
|
||||||
"google.golang.org/api/storage/v1"
|
"google.golang.org/api/storage/v1"
|
||||||
|
|
||||||
|
version "github.com/hashicorp/terraform/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
// accountFile represents the structure of the credentials JSON
|
// accountFile represents the structure of the credentials JSON
|
||||||
|
@ -99,7 +100,7 @@ func gcsFactory(conf map[string]string) (Client, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
versionString := terraform.Version
|
versionString := version.Version
|
||||||
userAgent := fmt.Sprintf(
|
userAgent := fmt.Sprintf(
|
||||||
"(%s %s) Terraform/%s", runtime.GOOS, runtime.GOARCH, versionString)
|
"(%s %s) Terraform/%s", runtime.GOOS, runtime.GOARCH, versionString)
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@ import (
|
||||||
|
|
||||||
uuid "github.com/hashicorp/go-uuid"
|
uuid "github.com/hashicorp/go-uuid"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
|
"github.com/hashicorp/terraform/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
var rngSource *rand.Rand
|
var rngSource *rand.Rand
|
||||||
|
@ -158,7 +159,7 @@ func NewLockInfo() *LockInfo {
|
||||||
info := &LockInfo{
|
info := &LockInfo{
|
||||||
ID: id,
|
ID: id,
|
||||||
Who: fmt.Sprintf("%s@%s", userName, host),
|
Who: fmt.Sprintf("%s@%s", userName, host),
|
||||||
Version: terraform.Version,
|
Version: version.Version,
|
||||||
Created: time.Now().UTC(),
|
Created: time.Now().UTC(),
|
||||||
}
|
}
|
||||||
return info
|
return info
|
||||||
|
|
|
@ -20,7 +20,7 @@ import (
|
||||||
cleanhttp "github.com/hashicorp/go-cleanhttp"
|
cleanhttp "github.com/hashicorp/go-cleanhttp"
|
||||||
"github.com/hashicorp/terraform/svchost"
|
"github.com/hashicorp/terraform/svchost"
|
||||||
"github.com/hashicorp/terraform/svchost/auth"
|
"github.com/hashicorp/terraform/svchost/auth"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -30,7 +30,7 @@ const (
|
||||||
maxDiscoDocBytes = 1 * 1024 * 1024 // 1MB - to prevent abusive services from using loads of our memory
|
maxDiscoDocBytes = 1 * 1024 * 1024 // 1MB - to prevent abusive services from using loads of our memory
|
||||||
)
|
)
|
||||||
|
|
||||||
var userAgent = fmt.Sprintf("Terraform/%s (service discovery)", terraform.VersionString())
|
var userAgent = fmt.Sprintf("Terraform/%s (service discovery)", version.String())
|
||||||
var httpTransport = cleanhttp.DefaultPooledTransport() // overridden during tests, to skip TLS verification
|
var httpTransport = cleanhttp.DefaultPooledTransport() // overridden during tests, to skip TLS verification
|
||||||
|
|
||||||
// Disco is the main type in this package, which allows discovery on given
|
// Disco is the main type in this package, which allows discovery on given
|
||||||
|
|
|
@ -12,6 +12,7 @@ import (
|
||||||
"github.com/hashicorp/hcl"
|
"github.com/hashicorp/hcl"
|
||||||
"github.com/hashicorp/terraform/config"
|
"github.com/hashicorp/terraform/config"
|
||||||
"github.com/hashicorp/terraform/config/module"
|
"github.com/hashicorp/terraform/config/module"
|
||||||
|
"github.com/hashicorp/terraform/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
// InputMode defines what sort of input will be asked for when Input
|
// InputMode defines what sort of input will be asked for when Input
|
||||||
|
@ -154,7 +155,7 @@ func NewContext(opts *ContextOpts) (*Context, error) {
|
||||||
// Explicitly reset our state version to our current version so that
|
// Explicitly reset our state version to our current version so that
|
||||||
// any operations we do will write out that our latest version
|
// any operations we do will write out that our latest version
|
||||||
// has run.
|
// has run.
|
||||||
state.TFVersion = Version
|
state.TFVersion = version.Version
|
||||||
|
|
||||||
// Determine parallelism, default to 10. We do this both to limit
|
// Determine parallelism, default to 10. We do this both to limit
|
||||||
// CPU pressure but also to have an extra guard against rate throttling
|
// CPU pressure but also to have an extra guard against rate throttling
|
||||||
|
@ -532,7 +533,7 @@ func (c *Context) Plan() (*Plan, error) {
|
||||||
State: c.state,
|
State: c.state,
|
||||||
Targets: c.targets,
|
Targets: c.targets,
|
||||||
|
|
||||||
TerraformVersion: VersionString(),
|
TerraformVersion: version.String(),
|
||||||
ProviderSHA256s: c.providerSHA256s,
|
ProviderSHA256s: c.providerSHA256s,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
|
|
||||||
"github.com/hashicorp/go-version"
|
"github.com/hashicorp/go-version"
|
||||||
"github.com/hashicorp/terraform/flatmap"
|
"github.com/hashicorp/terraform/flatmap"
|
||||||
|
tfversion "github.com/hashicorp/terraform/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNewContextRequiredVersion(t *testing.T) {
|
func TestNewContextRequiredVersion(t *testing.T) {
|
||||||
|
@ -62,9 +63,9 @@ func TestNewContextRequiredVersion(t *testing.T) {
|
||||||
for i, tc := range cases {
|
for i, tc := range cases {
|
||||||
t.Run(fmt.Sprintf("%d-%s", i, tc.Name), func(t *testing.T) {
|
t.Run(fmt.Sprintf("%d-%s", i, tc.Name), func(t *testing.T) {
|
||||||
// Reset the version for the tests
|
// Reset the version for the tests
|
||||||
old := SemVersion
|
old := tfversion.SemVer
|
||||||
SemVersion = version.Must(version.NewVersion(tc.Version))
|
tfversion.SemVer = version.Must(version.NewVersion(tc.Version))
|
||||||
defer func() { SemVersion = old }()
|
defer func() { tfversion.SemVer = old }()
|
||||||
|
|
||||||
name := "context-required-version"
|
name := "context-required-version"
|
||||||
if tc.Module != "" {
|
if tc.Module != "" {
|
||||||
|
@ -108,7 +109,7 @@ func TestNewContextState(t *testing.T) {
|
||||||
|
|
||||||
"equal TFVersion": {
|
"equal TFVersion": {
|
||||||
&ContextOpts{
|
&ContextOpts{
|
||||||
State: &State{TFVersion: Version},
|
State: &State{TFVersion: tfversion.Version},
|
||||||
},
|
},
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
|
@ -139,7 +140,7 @@ func TestNewContextState(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Version should always be set to our current
|
// Version should always be set to our current
|
||||||
if ctx.state.TFVersion != Version {
|
if ctx.state.TFVersion != tfversion.Version {
|
||||||
t.Fatalf("%s: state not set to current version", k)
|
t.Fatalf("%s: state not set to current version", k)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/config"
|
"github.com/hashicorp/terraform/config"
|
||||||
|
"github.com/hashicorp/terraform/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
// EvalCompareDiff is an EvalNode implementation that compares two diffs
|
// EvalCompareDiff is an EvalNode implementation that compares two diffs
|
||||||
|
@ -60,7 +61,7 @@ func (n *EvalCompareDiff) Eval(ctx EvalContext) (interface{}, error) {
|
||||||
"\n"+
|
"\n"+
|
||||||
"Also include as much context as you can about your config, state, "+
|
"Also include as much context as you can about your config, state, "+
|
||||||
"and the steps you performed to trigger this error.\n",
|
"and the steps you performed to trigger this error.\n",
|
||||||
n.Info.Id, Version, n.Info.Id, reason, one, two)
|
n.Info.Id, version.Version, n.Info.Id, reason, one, two)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, nil
|
return nil, nil
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/config/module"
|
"github.com/hashicorp/terraform/config/module"
|
||||||
|
"github.com/hashicorp/terraform/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -119,7 +120,7 @@ func (p *Plan) contextOpts(base *ContextOpts) (*ContextOpts, error) {
|
||||||
log.Println("[WARNING] Plan state and ContextOpts state are not equal")
|
log.Println("[WARNING] Plan state and ContextOpts state are not equal")
|
||||||
}
|
}
|
||||||
|
|
||||||
thisVersion := VersionString()
|
thisVersion := version.String()
|
||||||
if p.TerraformVersion != "" && p.TerraformVersion != thisVersion {
|
if p.TerraformVersion != "" && p.TerraformVersion != thisVersion {
|
||||||
return nil, fmt.Errorf(
|
return nil, fmt.Errorf(
|
||||||
"plan was created with a different version of Terraform (created with %s, but running %s)",
|
"plan was created with a different version of Terraform (created with %s, but running %s)",
|
||||||
|
|
|
@ -20,6 +20,8 @@ import (
|
||||||
"github.com/hashicorp/terraform/config"
|
"github.com/hashicorp/terraform/config"
|
||||||
"github.com/mitchellh/copystructure"
|
"github.com/mitchellh/copystructure"
|
||||||
"github.com/satori/go.uuid"
|
"github.com/satori/go.uuid"
|
||||||
|
|
||||||
|
tfversion "github.com/hashicorp/terraform/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -664,7 +666,7 @@ func (s *State) FromFutureTerraform() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
v := version.Must(version.NewVersion(s.TFVersion))
|
v := version.Must(version.NewVersion(s.TFVersion))
|
||||||
return SemVersion.LessThan(v)
|
return tfversion.SemVer.LessThan(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *State) Init() {
|
func (s *State) Init() {
|
||||||
|
@ -1908,7 +1910,7 @@ func ReadState(src io.Reader) (*State, error) {
|
||||||
result = v3State
|
result = v3State
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("Terraform %s does not support state version %d, please update.",
|
return nil, fmt.Errorf("Terraform %s does not support state version %d, please update.",
|
||||||
SemVersion.String(), versionIdentifier.Version)
|
tfversion.SemVer.String(), versionIdentifier.Version)
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we reached this place we must have a result set
|
// If we reached this place we must have a result set
|
||||||
|
@ -1952,7 +1954,7 @@ func ReadStateV2(jsonBytes []byte) (*State, error) {
|
||||||
// version that we don't understand
|
// version that we don't understand
|
||||||
if state.Version > StateVersion {
|
if state.Version > StateVersion {
|
||||||
return nil, fmt.Errorf("Terraform %s does not support state version %d, please update.",
|
return nil, fmt.Errorf("Terraform %s does not support state version %d, please update.",
|
||||||
SemVersion.String(), state.Version)
|
tfversion.SemVer.String(), state.Version)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure the version is semantic
|
// Make sure the version is semantic
|
||||||
|
@ -1987,7 +1989,7 @@ func ReadStateV3(jsonBytes []byte) (*State, error) {
|
||||||
// version that we don't understand
|
// version that we don't understand
|
||||||
if state.Version > StateVersion {
|
if state.Version > StateVersion {
|
||||||
return nil, fmt.Errorf("Terraform %s does not support state version %d, please update.",
|
return nil, fmt.Errorf("Terraform %s does not support state version %d, please update.",
|
||||||
SemVersion.String(), state.Version)
|
tfversion.SemVer.String(), state.Version)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure the version is semantic
|
// Make sure the version is semantic
|
||||||
|
|
|
@ -3,6 +3,8 @@ package terraform
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
|
"github.com/hashicorp/terraform/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
// The standard Terraform User-Agent format
|
// The standard Terraform User-Agent format
|
||||||
|
@ -10,5 +12,5 @@ const UserAgent = "Terraform %s (%s)"
|
||||||
|
|
||||||
// Generate a UserAgent string
|
// Generate a UserAgent string
|
||||||
func UserAgentString() string {
|
func UserAgentString() string {
|
||||||
return fmt.Sprintf(UserAgent, VersionString(), runtime.Version())
|
return fmt.Sprintf(UserAgent, version.String(), runtime.Version())
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,31 +1,10 @@
|
||||||
package terraform
|
package terraform
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"github.com/hashicorp/terraform/version"
|
||||||
|
|
||||||
"github.com/hashicorp/go-version"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// The main version number that is being run at the moment.
|
// TODO: update providers to use the version package directly
|
||||||
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 VersionPrerelease = "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))
|
|
||||||
|
|
||||||
// VersionHeader is the header name used to send the current terraform version
|
|
||||||
// in http requests.
|
|
||||||
const VersionHeader = "Terraform-Version"
|
|
||||||
|
|
||||||
func VersionString() string {
|
func VersionString() string {
|
||||||
if VersionPrerelease != "" {
|
return version.String()
|
||||||
return fmt.Sprintf("%s-%s", Version, VersionPrerelease)
|
|
||||||
}
|
|
||||||
return Version
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,8 @@ import (
|
||||||
"github.com/hashicorp/go-version"
|
"github.com/hashicorp/go-version"
|
||||||
"github.com/hashicorp/terraform/config"
|
"github.com/hashicorp/terraform/config"
|
||||||
"github.com/hashicorp/terraform/config/module"
|
"github.com/hashicorp/terraform/config/module"
|
||||||
|
|
||||||
|
tfversion "github.com/hashicorp/terraform/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CheckRequiredVersion verifies that any version requirements specified by
|
// CheckRequiredVersion verifies that any version requirements specified by
|
||||||
|
@ -49,7 +51,7 @@ func CheckRequiredVersion(m *module.Tree) error {
|
||||||
tf.RequiredVersion, err)
|
tf.RequiredVersion, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !cs.Check(SemVersion) {
|
if !cs.Check(tfversion.SemVer) {
|
||||||
return fmt.Errorf(
|
return fmt.Errorf(
|
||||||
"The currently running version of Terraform doesn't meet the\n"+
|
"The currently running version of Terraform doesn't meet the\n"+
|
||||||
"version requirements explicitly specified by the configuration.\n"+
|
"version requirements explicitly specified by the configuration.\n"+
|
||||||
|
@ -62,7 +64,7 @@ func CheckRequiredVersion(m *module.Tree) error {
|
||||||
" Current version: %s",
|
" Current version: %s",
|
||||||
module,
|
module,
|
||||||
tf.RequiredVersion,
|
tf.RequiredVersion,
|
||||||
SemVersion)
|
tfversion.SemVer)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import "github.com/hashicorp/terraform/terraform"
|
import (
|
||||||
|
"github.com/hashicorp/terraform/version"
|
||||||
|
)
|
||||||
|
|
||||||
// The git commit that was compiled. This will be filled in by the compiler.
|
// The git commit that was compiled. This will be filled in by the compiler.
|
||||||
var GitCommit string
|
var GitCommit string
|
||||||
|
|
||||||
const Version = terraform.Version
|
const Version = version.Version
|
||||||
|
|
||||||
var VersionPrerelease = terraform.VersionPrerelease
|
var VersionPrerelease = version.Prerelease
|
||||||
|
|
|
@ -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"
|
||||||
|
|
||||||
|
// SemVer 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 SemVer = 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 Prerelease != "" {
|
||||||
|
return fmt.Sprintf("%s-%s", Version, Prerelease)
|
||||||
|
}
|
||||||
|
return Version
|
||||||
|
}
|
Loading…
Reference in New Issue