Skip to content

Commit

Permalink
Make backcend/legacy match new Backend iface
Browse files Browse the repository at this point in the history
move the unsupported error value to backend.ErrNamedStatesNotSupported
to be used by any backend implementation.
  • Loading branch information
jbardin committed Feb 28, 2017
1 parent 65527f3 commit 5762878
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
4 changes: 4 additions & 0 deletions backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package backend

import (
"context"
"errors"

"github.com/hashicorp/terraform/config/module"
"github.com/hashicorp/terraform/state"
Expand All @@ -14,6 +15,9 @@ import (

const DefaultStateName = "default"

// Error value to return when a named state operation isn't supported
var ErrNamedStatesNotSupported = errors.New("named states not supported")

// Backend is the minimal interface that must be implemented to enable Terraform.
type Backend interface {
// Ask for input and configure the backend. Similar to
Expand Down
15 changes: 14 additions & 1 deletion backend/legacy/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ 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"
Expand Down Expand Up @@ -53,10 +54,22 @@ func (b *Backend) Configure(c *terraform.ResourceConfig) error {
return nil
}

func (b *Backend) State() (state.State, error) {
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
}
2 changes: 1 addition & 1 deletion backend/legacy/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestBackend(t *testing.T) {
}

// Grab state
s, err := b.State()
s, err := b.State(backend.DefaultStateName)
if err != nil {
t.Fatalf("err: %s", err)
}
Expand Down
2 changes: 0 additions & 2 deletions backend/local/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ const (
DefaultBackupExtension = ".backup"
)

var ErrEnvNotSupported = errors.New("environments not supported")

// Local is an implementation of EnhancedBackend that performs all operations
// locally. This is the "default" backend and implements normal Terraform
// behavior as it is well known.
Expand Down

0 comments on commit 5762878

Please sign in to comment.