From 761c63d14a850c8c2cf55553769291919cfdcc24 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Tue, 21 Feb 2017 10:48:00 -0500 Subject: [PATCH] Update Backend to incorporate environments Add the missing methods/arguments to handle Terraform environments in Backends. Extra functionality simply returns defaults for now. --- backend/backend.go | 9 +++++++++ backend/legacy/backend.go | 9 +++++++++ backend/local/backend.go | 8 ++++++++ backend/nil.go | 9 +++++++++ backend/remote-state/backend.go | 9 +++++++++ 5 files changed, 44 insertions(+) diff --git a/backend/backend.go b/backend/backend.go index 86f885207..da2e6daf1 100644 --- a/backend/backend.go +++ b/backend/backend.go @@ -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. diff --git a/backend/legacy/backend.go b/backend/legacy/backend.go index 21ed7b1fb..3fafb7e67 100644 --- a/backend/legacy/backend.go +++ b/backend/legacy/backend.go @@ -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 +} diff --git a/backend/local/backend.go b/backend/local/backend.go index 00704940c..1609c924d 100644 --- a/backend/local/backend.go +++ b/backend/local/backend.go @@ -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 { diff --git a/backend/nil.go b/backend/nil.go index 120ee4123..5482ca8a0 100644 --- a/backend/nil.go +++ b/backend/nil.go @@ -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 +} diff --git a/backend/remote-state/backend.go b/backend/remote-state/backend.go index bcb6912bc..8dd50e6f4 100644 --- a/backend/remote-state/backend.go +++ b/backend/remote-state/backend.go @@ -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 {