Update Backend to incorporate environments
Add the missing methods/arguments to handle Terraform environments in Backends. Extra functionality simply returns defaults for now.
This commit is contained in:
parent
03a8e32fed
commit
761c63d14a
|
@ -12,6 +12,8 @@ import (
|
|||
"github.com/hashicorp/terraform/terraform"
|
||||
)
|
||||
|
||||
const DefaultStateName = "default"
|
||||
|
||||
// Backend is the minimal interface that must be implemented to enable Terraform.
|
||||
type Backend interface {
|
||||
// Ask for input and configure the backend. Similar to
|
||||
|
@ -25,6 +27,13 @@ type Backend interface {
|
|||
// to load the state. If the state.State is a state.Locker, it's up to the
|
||||
// caller to call Lock and Unlock as needed.
|
||||
State() (state.State, error)
|
||||
|
||||
// States returns a list of configured named states and the current state.
|
||||
States() ([]string, string, error)
|
||||
|
||||
// ChangeState changes to the named state. If this doesn't exist it'll be
|
||||
// created.
|
||||
ChangeState(name string) error
|
||||
}
|
||||
|
||||
// Enhanced implements additional behavior on top of a normal backend.
|
||||
|
|
|
@ -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"
|
||||
|
@ -60,3 +61,11 @@ func (b *Backend) State() (state.State, error) {
|
|||
|
||||
return &remote.State{Client: b.client}, nil
|
||||
}
|
||||
|
||||
func (b *Backend) States() ([]string, string, error) {
|
||||
return []string{backend.DefaultStateName}, backend.DefaultStateName, nil
|
||||
}
|
||||
|
||||
func (b *Backend) ChangeState(name string) error {
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -96,6 +96,14 @@ func (b *Local) Configure(c *terraform.ResourceConfig) error {
|
|||
return f(c)
|
||||
}
|
||||
|
||||
func (b *Local) States() ([]string, string, error) {
|
||||
return []string{backend.DefaultStateName}, backend.DefaultStateName, nil
|
||||
}
|
||||
|
||||
func (b *Local) ChangeState(name string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *Local) State() (state.State, error) {
|
||||
// If we have a backend handling state, defer to that.
|
||||
if b.Backend != nil {
|
||||
|
|
|
@ -29,3 +29,12 @@ func (Nil) State() (state.State, error) {
|
|||
// We have to return a non-nil state to adhere to the interface
|
||||
return &state.InmemState{}, nil
|
||||
}
|
||||
|
||||
func (Nil) States() ([]string, string, error) {
|
||||
// The default state always exists
|
||||
return []string{DefaultStateName}, DefaultStateName, nil
|
||||
}
|
||||
|
||||
func (Nil) ChangeState(string) error {
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ package remotestate
|
|||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/terraform/backend"
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
"github.com/hashicorp/terraform/state"
|
||||
"github.com/hashicorp/terraform/state/remote"
|
||||
|
@ -46,6 +47,14 @@ func (b *Backend) Configure(rc *terraform.ResourceConfig) error {
|
|||
return b.Backend.Configure(rc)
|
||||
}
|
||||
|
||||
func (b *Backend) States() ([]string, string, error) {
|
||||
return []string{backend.DefaultStateName}, backend.DefaultStateName, nil
|
||||
}
|
||||
|
||||
func (b *Backend) ChangeState(name string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *Backend) State() (state.State, error) {
|
||||
// This shouldn't happen
|
||||
if b.client == nil {
|
||||
|
|
Loading…
Reference in New Issue