command: convert to using backend/init

This commit is contained in:
Mitchell Hashimoto 2017-02-22 11:17:27 -08:00
parent f79e04500f
commit 478a7dbfe7
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
1 changed files with 7 additions and 29 deletions

View File

@ -16,6 +16,7 @@ import (
"github.com/hashicorp/go-multierror"
"github.com/hashicorp/hcl"
"github.com/hashicorp/terraform/backend"
backendinit "github.com/hashicorp/terraform/backend/init"
clistate "github.com/hashicorp/terraform/command/state"
"github.com/hashicorp/terraform/config"
"github.com/hashicorp/terraform/state"
@ -24,8 +25,6 @@ import (
backendlegacy "github.com/hashicorp/terraform/backend/legacy"
backendlocal "github.com/hashicorp/terraform/backend/local"
backendconsul "github.com/hashicorp/terraform/backend/remote-state/consul"
backendinmem "github.com/hashicorp/terraform/backend/remote-state/inmem"
)
// BackendOpts are the options used to initialize a backend.Backend.
@ -1149,8 +1148,8 @@ func (m *Meta) backend_C_r_S_unchanged(
config := terraform.NewResourceConfig(rawC)
// Get the backend
f, ok := Backends[s.Backend.Type]
if !ok {
f := backendinit.Backend(s.Backend.Type)
if f == nil {
return nil, fmt.Errorf(strings.TrimSpace(errBackendSavedUnknown), s.Backend.Type)
}
b := f()
@ -1300,8 +1299,8 @@ func (m *Meta) backendInitFromConfig(c *config.Backend) (backend.Backend, error)
config := terraform.NewResourceConfig(c.RawConfig)
// Get the backend
f, ok := Backends[c.Type]
if !ok {
f := backendinit.Backend(c.Type)
if f == nil {
return nil, fmt.Errorf(strings.TrimSpace(errBackendNewUnknown), c.Type)
}
b := f()
@ -1374,8 +1373,8 @@ func (m *Meta) backendInitFromSaved(s *terraform.BackendState) (backend.Backend,
config := terraform.NewResourceConfig(rawC)
// Get the backend
f, ok := Backends[s.Type]
if !ok {
f := backendinit.Backend(s.Type)
if f == nil {
return nil, fmt.Errorf(strings.TrimSpace(errBackendSavedUnknown), s.Type)
}
b := f()
@ -1397,27 +1396,6 @@ func (m *Meta) backendInitRequired(reason string) {
// Output constants and initialization code
//-------------------------------------------------------------------
// Backends is the list of available backends. This is currently a hardcoded
// list that can't be modified without recompiling Terraform. This is done
// because the API for backends uses complex structures and supporting that
// over the plugin system is currently prohibitively difficult. For those
// wanting to implement a custom backend, recompilation should not be a
// high barrier.
var Backends map[string]func() backend.Backend
func init() {
// Our hardcoded backends
Backends = map[string]func() backend.Backend{
"local": func() backend.Backend { return &backendlocal.Local{} },
"consul": func() backend.Backend { return backendconsul.New() },
"inmem": func() backend.Backend { return backendinmem.New() },
}
// Add the legacy remote backends that haven't yet been convertd to
// the new backend API.
backendlegacy.Init(Backends)
}
// errBackendInitRequired is the final error message shown when reinit
// is required for some reason. The error message includes the reason.
var errBackendInitRequired = errors.New(