From f8321b8d7995854d84eafbfccfbd7d04b5f1bfb5 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Tue, 20 Mar 2018 17:19:15 -0400 Subject: [PATCH] remove legacy remote state code --- backend/init/init.go | 5 --- backend/legacy/backend.go | 75 ---------------------------------- backend/legacy/backend_test.go | 50 ----------------------- backend/legacy/legacy.go | 28 ------------- backend/legacy/legacy_test.go | 34 --------------- 5 files changed, 192 deletions(-) delete mode 100644 backend/legacy/backend.go delete mode 100644 backend/legacy/backend_test.go delete mode 100644 backend/legacy/legacy.go delete mode 100644 backend/legacy/legacy_test.go diff --git a/backend/init/init.go b/backend/init/init.go index efe6321f27..d2ec76368f 100644 --- a/backend/init/init.go +++ b/backend/init/init.go @@ -9,7 +9,6 @@ import ( "github.com/hashicorp/terraform/terraform" backendatlas "github.com/hashicorp/terraform/backend/atlas" - backendlegacy "github.com/hashicorp/terraform/backend/legacy" backendlocal "github.com/hashicorp/terraform/backend/local" backendartifactory "github.com/hashicorp/terraform/backend/remote-state/artifactory" backendAzure "github.com/hashicorp/terraform/backend/remote-state/azure" @@ -58,10 +57,6 @@ func init() { "gcs": func() backend.Backend { return backendGCS.New() }, "manta": func() backend.Backend { return backendManta.New() }, } - - // Add the legacy remote backends that haven't yet been convertd to - // the new backend API. - backendlegacy.Init(backends) } // Backend returns the initialization factory for the given backend, or diff --git a/backend/legacy/backend.go b/backend/legacy/backend.go deleted file mode 100644 index a8b0cad9fb..0000000000 --- a/backend/legacy/backend.go +++ /dev/null @@ -1,75 +0,0 @@ -package legacy - -import ( - "fmt" - - "github.com/hashicorp/terraform/backend" - "github.com/hashicorp/terraform/state" - "github.com/hashicorp/terraform/state/remote" - "github.com/hashicorp/terraform/terraform" - "github.com/mitchellh/mapstructure" -) - -// Backend is an implementation of backend.Backend for legacy remote state -// clients. -type Backend struct { - // Type is the type of remote state client to support - Type string - - // client is set after Configure is called and client is initialized. - client remote.Client -} - -func (b *Backend) Input( - ui terraform.UIInput, c *terraform.ResourceConfig) (*terraform.ResourceConfig, error) { - // Return the config as-is, legacy doesn't support input - return c, nil -} - -func (b *Backend) Validate(*terraform.ResourceConfig) ([]string, []error) { - // No validation was supported for old clients - return nil, nil -} - -func (b *Backend) Configure(c *terraform.ResourceConfig) error { - // Legacy remote state was only map[string]string config - var conf map[string]string - if err := mapstructure.Decode(c.Raw, &conf); err != nil { - return fmt.Errorf( - "Failed to decode %q configuration: %s\n\n"+ - "This backend expects all configuration keys and values to be\n"+ - "strings. Please verify your configuration and try again.", - b.Type, err) - } - - client, err := remote.NewClient(b.Type, conf) - if err != nil { - return fmt.Errorf( - "Failed to configure remote backend %q: %s", - b.Type, err) - } - - // Set our client - b.client = client - return nil -} - -func (b *Backend) State(name string) (state.State, error) { - if name != backend.DefaultStateName { - return nil, backend.ErrNamedStatesNotSupported - } - - if b.client == nil { - panic("State called with nil remote state client") - } - - return &remote.State{Client: b.client}, nil -} - -func (b *Backend) States() ([]string, error) { - return nil, backend.ErrNamedStatesNotSupported -} - -func (b *Backend) DeleteState(string) error { - return backend.ErrNamedStatesNotSupported -} diff --git a/backend/legacy/backend_test.go b/backend/legacy/backend_test.go deleted file mode 100644 index 9eeb3a0c7f..0000000000 --- a/backend/legacy/backend_test.go +++ /dev/null @@ -1,50 +0,0 @@ -package legacy - -import ( - "io/ioutil" - "os" - "path/filepath" - "testing" - - "github.com/hashicorp/terraform/backend" - "github.com/hashicorp/terraform/config" - "github.com/hashicorp/terraform/state" - "github.com/hashicorp/terraform/terraform" -) - -func TestBackend_impl(t *testing.T) { - var _ backend.Backend = new(Backend) -} - -func TestBackend(t *testing.T) { - t.Skip() - td, err := ioutil.TempDir("", "tf") - if err != nil { - t.Fatalf("err: %s", err) - } - defer os.RemoveAll(td) - - b := &Backend{Type: "local"} - conf := terraform.NewResourceConfig(config.TestRawConfig(t, map[string]interface{}{ - "path": filepath.Join(td, "data"), - })) - - // Config - if err := b.Configure(conf); err != nil { - t.Fatalf("err: %s", err) - } - - // Grab state - s, err := b.State(backend.DefaultStateName) - if err != nil { - t.Fatalf("err: %s", err) - } - if s == nil { - t.Fatalf("state is nil") - } - - // Test it - s.WriteState(state.TestStateInitial()) - s.PersistState() - state.TestState(t, s) -} diff --git a/backend/legacy/legacy.go b/backend/legacy/legacy.go deleted file mode 100644 index be3163bd53..0000000000 --- a/backend/legacy/legacy.go +++ /dev/null @@ -1,28 +0,0 @@ -// Package legacy contains a backend implementation that can be used -// with the legacy remote state clients. -package legacy - -import ( - "github.com/hashicorp/terraform/backend" - "github.com/hashicorp/terraform/state/remote" -) - -// Init updates the backend/init package map of initializers to support -// all the remote state types. -// -// If a type is already in the map, it will not be added. This will allow -// us to slowly convert the legacy types to first-class backends. -func Init(m map[string]func() backend.Backend) { - for k, _ := range remote.BuiltinClients { - if _, ok := m[k]; !ok { - // Copy the "k" value since the variable "k" is reused for - // each key (address doesn't change). - typ := k - - // Build the factory function to return a backend of typ - m[k] = func() backend.Backend { - return &Backend{Type: typ} - } - } - } -} diff --git a/backend/legacy/legacy_test.go b/backend/legacy/legacy_test.go deleted file mode 100644 index 77d81bf1ae..0000000000 --- a/backend/legacy/legacy_test.go +++ /dev/null @@ -1,34 +0,0 @@ -package legacy - -import ( - "testing" - - "github.com/hashicorp/terraform/backend" - "github.com/hashicorp/terraform/state/remote" -) - -func TestInit(t *testing.T) { - m := make(map[string]func() backend.Backend) - Init(m) - - for k, _ := range remote.BuiltinClients { - b, ok := m[k] - if !ok { - t.Fatalf("missing: %s", k) - } - - if typ := b().(*Backend).Type; typ != k { - t.Fatalf("bad type: %s", typ) - } - } -} - -func TestInit_ignoreExisting(t *testing.T) { - m := make(map[string]func() backend.Backend) - m["local"] = nil - Init(m) - - if v, ok := m["local"]; !ok || v != nil { - t.Fatalf("bad: %#v", m) - } -}