remove legacy types from command package
This commit is contained in:
parent
c33b8c7faa
commit
e998882824
|
@ -12,8 +12,8 @@ import (
|
|||
"time"
|
||||
|
||||
multierror "github.com/hashicorp/go-multierror"
|
||||
"github.com/hashicorp/terraform/internal/legacy/terraform"
|
||||
"github.com/hashicorp/terraform/states/statemgr"
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
)
|
||||
|
||||
// LocalState manages a state storage that is local to the filesystem.
|
||||
|
|
|
@ -41,6 +41,7 @@ import (
|
|||
|
||||
backendInit "github.com/hashicorp/terraform/backend/init"
|
||||
backendLocal "github.com/hashicorp/terraform/backend/local"
|
||||
legacy "github.com/hashicorp/terraform/internal/legacy/terraform"
|
||||
_ "github.com/hashicorp/terraform/internal/logging"
|
||||
)
|
||||
|
||||
|
@ -404,7 +405,7 @@ func testStateFileWorkspaceDefault(t *testing.T, workspace string, s *states.Sta
|
|||
|
||||
// testStateFileRemote writes the state out to the remote statefile
|
||||
// in the cwd. Use `testCwd` to change into a temp cwd.
|
||||
func testStateFileRemote(t *testing.T, s *terraform.State) string {
|
||||
func testStateFileRemote(t *testing.T, s *legacy.State) string {
|
||||
t.Helper()
|
||||
|
||||
path := filepath.Join(DefaultDataDir, DefaultStateFilename)
|
||||
|
@ -418,7 +419,7 @@ func testStateFileRemote(t *testing.T, s *terraform.State) string {
|
|||
}
|
||||
defer f.Close()
|
||||
|
||||
if err := terraform.WriteState(s, f); err != nil {
|
||||
if err := legacy.WriteState(s, f); err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
|
@ -446,9 +447,9 @@ func testStateRead(t *testing.T, path string) *states.State {
|
|||
// testDataStateRead reads a "data state", which is a file format resembling
|
||||
// our state format v3 that is used only to track current backend settings.
|
||||
//
|
||||
// This old format still uses *terraform.State, but should be replaced with
|
||||
// This old format still uses *legacy.State, but should be replaced with
|
||||
// a more specialized type in a later release.
|
||||
func testDataStateRead(t *testing.T, path string) *terraform.State {
|
||||
func testDataStateRead(t *testing.T, path string) *legacy.State {
|
||||
t.Helper()
|
||||
|
||||
f, err := os.Open(path)
|
||||
|
@ -457,7 +458,7 @@ func testDataStateRead(t *testing.T, path string) *terraform.State {
|
|||
}
|
||||
defer f.Close()
|
||||
|
||||
s, err := terraform.ReadState(f)
|
||||
s, err := legacy.ReadState(f)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
@ -719,7 +720,7 @@ func testInputMap(t *testing.T, answers map[string]string) func() {
|
|||
// be returned about the backend configuration having changed and that
|
||||
// "terraform init" must be run, since the test backend config cache created
|
||||
// by this function contains the hash for an empty configuration.
|
||||
func testBackendState(t *testing.T, s *states.State, c int) (*terraform.State, *httptest.Server) {
|
||||
func testBackendState(t *testing.T, s *states.State, c int) (*legacy.State, *httptest.Server) {
|
||||
t.Helper()
|
||||
|
||||
var b64md5 string
|
||||
|
@ -759,8 +760,8 @@ func testBackendState(t *testing.T, s *states.State, c int) (*terraform.State, *
|
|||
configSchema := b.ConfigSchema()
|
||||
hash := backendConfig.Hash(configSchema)
|
||||
|
||||
state := terraform.NewState()
|
||||
state.Backend = &terraform.BackendState{
|
||||
state := legacy.NewState()
|
||||
state.Backend = &legacy.BackendState{
|
||||
Type: "http",
|
||||
ConfigRaw: json.RawMessage(fmt.Sprintf(`{"address":%q}`, srv.URL)),
|
||||
Hash: uint64(hash),
|
||||
|
@ -772,10 +773,10 @@ func testBackendState(t *testing.T, s *states.State, c int) (*terraform.State, *
|
|||
// testRemoteState is used to make a test HTTP server to return a given
|
||||
// state file that can be used for testing legacy remote state.
|
||||
//
|
||||
// The return values are a *terraform.State instance that should be written
|
||||
// The return values are a *legacy.State instance that should be written
|
||||
// as the "data state" (really: backend state) and the server that the
|
||||
// returned data state refers to.
|
||||
func testRemoteState(t *testing.T, s *states.State, c int) (*terraform.State, *httptest.Server) {
|
||||
func testRemoteState(t *testing.T, s *states.State, c int) (*legacy.State, *httptest.Server) {
|
||||
t.Helper()
|
||||
|
||||
var b64md5 string
|
||||
|
@ -795,10 +796,10 @@ func testRemoteState(t *testing.T, s *states.State, c int) (*terraform.State, *h
|
|||
resp.Write(buf.Bytes())
|
||||
}
|
||||
|
||||
retState := terraform.NewState()
|
||||
retState := legacy.NewState()
|
||||
|
||||
srv := httptest.NewServer(http.HandlerFunc(cb))
|
||||
b := &terraform.BackendState{
|
||||
b := &legacy.BackendState{
|
||||
Type: "http",
|
||||
}
|
||||
b.SetConfig(cty.ObjectVal(map[string]cty.Value{
|
||||
|
|
|
@ -31,6 +31,8 @@ import (
|
|||
"github.com/hashicorp/terraform/tfdiags"
|
||||
"github.com/mitchellh/cli"
|
||||
"github.com/mitchellh/colorstring"
|
||||
|
||||
legacy "github.com/hashicorp/terraform/internal/legacy/terraform"
|
||||
)
|
||||
|
||||
// Meta are the meta-options that are available on all or most commands.
|
||||
|
@ -147,7 +149,7 @@ type Meta struct {
|
|||
configLoader *configload.Loader
|
||||
|
||||
// backendState is the currently active backend state
|
||||
backendState *terraform.BackendState
|
||||
backendState *legacy.BackendState
|
||||
|
||||
// Variables for the context (private)
|
||||
variableArgs rawFlags
|
||||
|
|
|
@ -29,6 +29,7 @@ import (
|
|||
|
||||
backendInit "github.com/hashicorp/terraform/backend/init"
|
||||
backendLocal "github.com/hashicorp/terraform/backend/local"
|
||||
legacy "github.com/hashicorp/terraform/internal/legacy/terraform"
|
||||
)
|
||||
|
||||
// BackendOpts are the options used to initialize a backend.Backend.
|
||||
|
@ -160,7 +161,7 @@ func (m *Meta) Backend(opts *BackendOpts) (backend.Enhanced, tfdiags.Diagnostics
|
|||
// with inside backendFromConfig, because we still need that codepath
|
||||
// to be able to recognize the lack of a config as distinct from
|
||||
// explicitly setting local until we do some more refactoring here.
|
||||
m.backendState = &terraform.BackendState{
|
||||
m.backendState = &legacy.BackendState{
|
||||
Type: "local",
|
||||
ConfigRaw: json.RawMessage("{}"),
|
||||
}
|
||||
|
@ -461,7 +462,7 @@ func (m *Meta) backendFromConfig(opts *BackendOpts) (backend.Backend, tfdiags.Di
|
|||
s := sMgr.State()
|
||||
if s == nil {
|
||||
log.Printf("[TRACE] Meta.Backend: backend has not previously been initialized in this working directory")
|
||||
s = terraform.NewState()
|
||||
s = legacy.NewState()
|
||||
} else if s.Backend != nil {
|
||||
log.Printf("[TRACE] Meta.Backend: working directory was previously initialized for %q backend", s.Backend.Type)
|
||||
} else {
|
||||
|
@ -818,9 +819,9 @@ func (m *Meta) backend_C_r_s(c *configs.Backend, cHash int, sMgr *clistate.Local
|
|||
// Store the metadata in our saved state location
|
||||
s := sMgr.State()
|
||||
if s == nil {
|
||||
s = terraform.NewState()
|
||||
s = legacy.NewState()
|
||||
}
|
||||
s.Backend = &terraform.BackendState{
|
||||
s.Backend = &legacy.BackendState{
|
||||
Type: c.Type,
|
||||
ConfigRaw: json.RawMessage(configJSON),
|
||||
Hash: uint64(cHash),
|
||||
|
@ -902,9 +903,9 @@ func (m *Meta) backend_C_r_S_changed(c *configs.Backend, cHash int, sMgr *clista
|
|||
// Update the backend state
|
||||
s = sMgr.State()
|
||||
if s == nil {
|
||||
s = terraform.NewState()
|
||||
s = legacy.NewState()
|
||||
}
|
||||
s.Backend = &terraform.BackendState{
|
||||
s.Backend = &legacy.BackendState{
|
||||
Type: c.Type,
|
||||
ConfigRaw: json.RawMessage(configJSON),
|
||||
Hash: uint64(cHash),
|
||||
|
@ -996,7 +997,7 @@ func (m *Meta) backend_C_r_S_unchanged(c *configs.Backend, cHash int, sMgr *clis
|
|||
// this function will conservatively assume that migration is required,
|
||||
// expecting that the migration code will subsequently deal with the same
|
||||
// errors.
|
||||
func (m *Meta) backendConfigNeedsMigration(c *configs.Backend, s *terraform.BackendState) bool {
|
||||
func (m *Meta) backendConfigNeedsMigration(c *configs.Backend, s *legacy.BackendState) bool {
|
||||
if s == nil || s.Empty() {
|
||||
log.Print("[TRACE] backendConfigNeedsMigration: no cached config, so migration is required")
|
||||
return true
|
||||
|
|
|
@ -18,7 +18,6 @@ import (
|
|||
tfplugin "github.com/hashicorp/terraform/plugin"
|
||||
"github.com/hashicorp/terraform/plugin/discovery"
|
||||
"github.com/hashicorp/terraform/provisioners"
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
)
|
||||
|
||||
// NOTE WELL: The logic in this file is primarily about plugin types OTHER THAN
|
||||
|
@ -120,7 +119,7 @@ func (m *Meta) pluginDirs(includeAutoInstalled bool) []string {
|
|||
return dirs
|
||||
}
|
||||
|
||||
func (m *Meta) provisionerFactories() map[string]terraform.ProvisionerFactory {
|
||||
func (m *Meta) provisionerFactories() map[string]provisioners.Factory {
|
||||
dirs := m.pluginDirs(true)
|
||||
plugins := discovery.FindPlugins("provisioner", dirs)
|
||||
plugins, _ = plugins.ValidateVersions()
|
||||
|
@ -131,7 +130,7 @@ func (m *Meta) provisionerFactories() map[string]terraform.ProvisionerFactory {
|
|||
// name here, even though the discovery interface forces us to pretend
|
||||
// that might not be true.
|
||||
|
||||
factories := make(map[string]terraform.ProvisionerFactory)
|
||||
factories := make(map[string]provisioners.Factory)
|
||||
|
||||
// Wire up the internal provisioners first. These might be overridden
|
||||
// by discovered provisioners below.
|
||||
|
@ -175,7 +174,7 @@ func internalPluginClient(kind, name string) (*plugin.Client, error) {
|
|||
return plugin.NewClient(cfg), nil
|
||||
}
|
||||
|
||||
func provisionerFactory(meta discovery.PluginMeta) terraform.ProvisionerFactory {
|
||||
func provisionerFactory(meta discovery.PluginMeta) provisioners.Factory {
|
||||
return func() (provisioners.Interface, error) {
|
||||
cfg := &plugin.ClientConfig{
|
||||
Cmd: exec.Command(meta.Path),
|
||||
|
@ -191,7 +190,7 @@ func provisionerFactory(meta discovery.PluginMeta) terraform.ProvisionerFactory
|
|||
}
|
||||
}
|
||||
|
||||
func internalProvisionerFactory(meta discovery.PluginMeta) terraform.ProvisionerFactory {
|
||||
func internalProvisionerFactory(meta discovery.PluginMeta) provisioners.Factory {
|
||||
return func() (provisioners.Interface, error) {
|
||||
client, err := internalPluginClient("provisioner", meta.Name)
|
||||
if err != nil {
|
||||
|
|
|
@ -5,8 +5,9 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/hashicorp/terraform/backend/remote-state/inmem"
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
"github.com/mitchellh/cli"
|
||||
|
||||
legacy "github.com/hashicorp/terraform/internal/legacy/terraform"
|
||||
)
|
||||
|
||||
// Since we can't unlock a local state file, just test that calling unlock
|
||||
|
@ -24,7 +25,7 @@ func TestUnlock(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
err = terraform.WriteState(terraform.NewState(), f)
|
||||
err = legacy.WriteState(legacy.NewState(), f)
|
||||
f.Close()
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
|
|
|
@ -13,8 +13,9 @@ import (
|
|||
"github.com/hashicorp/terraform/backend/remote-state/inmem"
|
||||
"github.com/hashicorp/terraform/states"
|
||||
"github.com/hashicorp/terraform/states/statemgr"
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
"github.com/mitchellh/cli"
|
||||
|
||||
legacy "github.com/hashicorp/terraform/internal/legacy/terraform"
|
||||
)
|
||||
|
||||
func TestWorkspace_createAndChange(t *testing.T) {
|
||||
|
@ -379,14 +380,14 @@ func TestWorkspace_deleteWithState(t *testing.T) {
|
|||
}
|
||||
|
||||
// create a non-empty state
|
||||
originalState := &terraform.State{
|
||||
Modules: []*terraform.ModuleState{
|
||||
&terraform.ModuleState{
|
||||
originalState := &legacy.State{
|
||||
Modules: []*legacy.ModuleState{
|
||||
&legacy.ModuleState{
|
||||
Path: []string{"root"},
|
||||
Resources: map[string]*terraform.ResourceState{
|
||||
"test_instance.foo": &terraform.ResourceState{
|
||||
Resources: map[string]*legacy.ResourceState{
|
||||
"test_instance.foo": &legacy.ResourceState{
|
||||
Type: "test_instance",
|
||||
Primary: &terraform.InstanceState{
|
||||
Primary: &legacy.InstanceState{
|
||||
ID: "bar",
|
||||
},
|
||||
},
|
||||
|
@ -400,7 +401,7 @@ func TestWorkspace_deleteWithState(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
defer f.Close()
|
||||
if err := terraform.WriteState(originalState, f); err != nil {
|
||||
if err := legacy.WriteState(originalState, f); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue