Skip to content

Commit 36b8be4

Browse files
committed
use the new version package
Update all references to the version values to use the new package. The VersionString function was left in the terraform package specifically for the aws provider, which is vendored. We can remove that last call once the provider is updated.
1 parent 3f6a7f3 commit 36b8be4

15 files changed

Lines changed: 50 additions & 56 deletions

File tree

‎command/push.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"github.com/hashicorp/atlas-go/v1"
1313
"github.com/hashicorp/terraform/backend"
1414
"github.com/hashicorp/terraform/config"
15-
"github.com/hashicorp/terraform/terraform"
15+
"github.com/hashicorp/terraform/version"
1616
)
1717

1818
type PushCommand struct {
@@ -174,7 +174,7 @@ func (c *PushCommand) Run(args []string) int {
174174
}
175175
}
176176

177-
client.DefaultHeader.Set(terraform.VersionHeader, terraform.Version)
177+
client.DefaultHeader.Set(version.Header, version.Version)
178178

179179
if atlasToken != "" {
180180
client.Token = atlasToken

‎command/refresh_test.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/hashicorp/terraform/helper/copy"
1313
"github.com/hashicorp/terraform/state"
1414
"github.com/hashicorp/terraform/terraform"
15+
"github.com/hashicorp/terraform/version"
1516
"github.com/mitchellh/cli"
1617
)
1718

@@ -353,7 +354,7 @@ func TestRefresh_pastState(t *testing.T) {
353354
t.Fatalf("bad:\n\n%s", actual)
354355
}
355356

356-
if newState.TFVersion != terraform.Version {
357+
if newState.TFVersion != version.Version {
357358
t.Fatalf("bad:\n\n%s", newState.TFVersion)
358359
}
359360
}

‎state/remote/gcs.go‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@ import (
1212
"strings"
1313

1414
"github.com/hashicorp/terraform/helper/pathorcontents"
15-
"github.com/hashicorp/terraform/terraform"
1615
"golang.org/x/net/context"
1716
"golang.org/x/oauth2"
1817
"golang.org/x/oauth2/google"
1918
"golang.org/x/oauth2/jwt"
2019
"google.golang.org/api/googleapi"
2120
"google.golang.org/api/storage/v1"
21+
22+
version "github.com/hashicorp/terraform/version"
2223
)
2324

2425
// accountFile represents the structure of the credentials JSON
@@ -99,7 +100,7 @@ func gcsFactory(conf map[string]string) (Client, error) {
99100
return nil, err
100101
}
101102
}
102-
versionString := terraform.Version
103+
versionString := version.Version
103104
userAgent := fmt.Sprintf(
104105
"(%s %s) Terraform/%s", runtime.GOOS, runtime.GOARCH, versionString)
105106

‎state/state.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515

1616
uuid "github.com/hashicorp/go-uuid"
1717
"github.com/hashicorp/terraform/terraform"
18+
"github.com/hashicorp/terraform/version"
1819
)
1920

2021
var rngSource *rand.Rand
@@ -158,7 +159,7 @@ func NewLockInfo() *LockInfo {
158159
info := &LockInfo{
159160
ID: id,
160161
Who: fmt.Sprintf("%s@%s", userName, host),
161-
Version: terraform.Version,
162+
Version: version.Version,
162163
Created: time.Now().UTC(),
163164
}
164165
return info

‎svchost/disco/disco.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
cleanhttp "github.com/hashicorp/go-cleanhttp"
2121
"github.com/hashicorp/terraform/svchost"
2222
"github.com/hashicorp/terraform/svchost/auth"
23-
"github.com/hashicorp/terraform/terraform"
23+
"github.com/hashicorp/terraform/version"
2424
)
2525

2626
const (
@@ -30,7 +30,7 @@ const (
3030
maxDiscoDocBytes = 1 * 1024 * 1024 // 1MB - to prevent abusive services from using loads of our memory
3131
)
3232

33-
var userAgent = fmt.Sprintf("Terraform/%s (service discovery)", terraform.VersionString())
33+
var userAgent = fmt.Sprintf("Terraform/%s (service discovery)", version.String())
3434
var httpTransport = cleanhttp.DefaultPooledTransport() // overridden during tests, to skip TLS verification
3535

3636
// Disco is the main type in this package, which allows discovery on given

‎terraform/context.go‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/hashicorp/hcl"
1313
"github.com/hashicorp/terraform/config"
1414
"github.com/hashicorp/terraform/config/module"
15+
"github.com/hashicorp/terraform/version"
1516
)
1617

1718
// InputMode defines what sort of input will be asked for when Input
@@ -154,7 +155,7 @@ func NewContext(opts *ContextOpts) (*Context, error) {
154155
// Explicitly reset our state version to our current version so that
155156
// any operations we do will write out that our latest version
156157
// has run.
157-
state.TFVersion = Version
158+
state.TFVersion = version.Version
158159

159160
// Determine parallelism, default to 10. We do this both to limit
160161
// CPU pressure but also to have an extra guard against rate throttling
@@ -532,7 +533,7 @@ func (c *Context) Plan() (*Plan, error) {
532533
State: c.state,
533534
Targets: c.targets,
534535

535-
TerraformVersion: VersionString(),
536+
TerraformVersion: version.String(),
536537
ProviderSHA256s: c.providerSHA256s,
537538
}
538539

‎terraform/context_test.go‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"github.com/hashicorp/go-version"
1010
"github.com/hashicorp/terraform/flatmap"
11+
tfversion "github.com/hashicorp/terraform/version"
1112
)
1213

1314
func TestNewContextRequiredVersion(t *testing.T) {
@@ -62,9 +63,9 @@ func TestNewContextRequiredVersion(t *testing.T) {
6263
for i, tc := range cases {
6364
t.Run(fmt.Sprintf("%d-%s", i, tc.Name), func(t *testing.T) {
6465
// Reset the version for the tests
65-
old := SemVersion
66-
SemVersion = version.Must(version.NewVersion(tc.Version))
67-
defer func() { SemVersion = old }()
66+
old := tfversion.SemVer
67+
tfversion.SemVer = version.Must(version.NewVersion(tc.Version))
68+
defer func() { tfversion.SemVer = old }()
6869

6970
name := "context-required-version"
7071
if tc.Module != "" {
@@ -108,7 +109,7 @@ func TestNewContextState(t *testing.T) {
108109

109110
"equal TFVersion": {
110111
&ContextOpts{
111-
State: &State{TFVersion: Version},
112+
State: &State{TFVersion: tfversion.Version},
112113
},
113114
false,
114115
},
@@ -139,7 +140,7 @@ func TestNewContextState(t *testing.T) {
139140
}
140141

141142
// Version should always be set to our current
142-
if ctx.state.TFVersion != Version {
143+
if ctx.state.TFVersion != tfversion.Version {
143144
t.Fatalf("%s: state not set to current version", k)
144145
}
145146
}

‎terraform/eval_diff.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"strings"
77

88
"github.com/hashicorp/terraform/config"
9+
"github.com/hashicorp/terraform/version"
910
)
1011

1112
// EvalCompareDiff is an EvalNode implementation that compares two diffs
@@ -60,7 +61,7 @@ func (n *EvalCompareDiff) Eval(ctx EvalContext) (interface{}, error) {
6061
"\n"+
6162
"Also include as much context as you can about your config, state, "+
6263
"and the steps you performed to trigger this error.\n",
63-
n.Info.Id, Version, n.Info.Id, reason, one, two)
64+
n.Info.Id, version.Version, n.Info.Id, reason, one, two)
6465
}
6566

6667
return nil, nil

‎terraform/plan.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"sync"
1111

1212
"github.com/hashicorp/terraform/config/module"
13+
"github.com/hashicorp/terraform/version"
1314
)
1415

1516
func init() {
@@ -119,7 +120,7 @@ func (p *Plan) contextOpts(base *ContextOpts) (*ContextOpts, error) {
119120
log.Println("[WARNING] Plan state and ContextOpts state are not equal")
120121
}
121122

122-
thisVersion := VersionString()
123+
thisVersion := version.String()
123124
if p.TerraformVersion != "" && p.TerraformVersion != thisVersion {
124125
return nil, fmt.Errorf(
125126
"plan was created with a different version of Terraform (created with %s, but running %s)",

‎terraform/state.go‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import (
2020
"github.com/hashicorp/terraform/config"
2121
"github.com/mitchellh/copystructure"
2222
"github.com/satori/go.uuid"
23+
24+
tfversion "github.com/hashicorp/terraform/version"
2325
)
2426

2527
const (
@@ -664,7 +666,7 @@ func (s *State) FromFutureTerraform() bool {
664666
}
665667

666668
v := version.Must(version.NewVersion(s.TFVersion))
667-
return SemVersion.LessThan(v)
669+
return tfversion.SemVer.LessThan(v)
668670
}
669671

670672
func (s *State) Init() {
@@ -1908,7 +1910,7 @@ func ReadState(src io.Reader) (*State, error) {
19081910
result = v3State
19091911
default:
19101912
return nil, fmt.Errorf("Terraform %s does not support state version %d, please update.",
1911-
SemVersion.String(), versionIdentifier.Version)
1913+
tfversion.SemVer.String(), versionIdentifier.Version)
19121914
}
19131915

19141916
// If we reached this place we must have a result set
@@ -1952,7 +1954,7 @@ func ReadStateV2(jsonBytes []byte) (*State, error) {
19521954
// version that we don't understand
19531955
if state.Version > StateVersion {
19541956
return nil, fmt.Errorf("Terraform %s does not support state version %d, please update.",
1955-
SemVersion.String(), state.Version)
1957+
tfversion.SemVer.String(), state.Version)
19561958
}
19571959

19581960
// Make sure the version is semantic
@@ -1987,7 +1989,7 @@ func ReadStateV3(jsonBytes []byte) (*State, error) {
19871989
// version that we don't understand
19881990
if state.Version > StateVersion {
19891991
return nil, fmt.Errorf("Terraform %s does not support state version %d, please update.",
1990-
SemVersion.String(), state.Version)
1992+
tfversion.SemVer.String(), state.Version)
19911993
}
19921994

19931995
// Make sure the version is semantic

0 commit comments

Comments
 (0)