Make backcend/legacy match new Backend iface
move the unsupported error value to backend.ErrNamedStatesNotSupported to be used by any backend implementation.
This commit is contained in:
parent
65527f35a4
commit
5762878eba
|
@ -6,6 +6,7 @@ package backend
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"github.com/hashicorp/terraform/config/module"
|
||||
"github.com/hashicorp/terraform/state"
|
||||
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue