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/go-multierror"
"github.com/hashicorp/hcl" "github.com/hashicorp/hcl"
"github.com/hashicorp/terraform/backend" "github.com/hashicorp/terraform/backend"
backendinit "github.com/hashicorp/terraform/backend/init"
clistate "github.com/hashicorp/terraform/command/state" clistate "github.com/hashicorp/terraform/command/state"
"github.com/hashicorp/terraform/config" "github.com/hashicorp/terraform/config"
"github.com/hashicorp/terraform/state" "github.com/hashicorp/terraform/state"
@ -24,8 +25,6 @@ import (
backendlegacy "github.com/hashicorp/terraform/backend/legacy" backendlegacy "github.com/hashicorp/terraform/backend/legacy"
backendlocal "github.com/hashicorp/terraform/backend/local" 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. // 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) config := terraform.NewResourceConfig(rawC)
// Get the backend // Get the backend
f, ok := Backends[s.Backend.Type] f := backendinit.Backend(s.Backend.Type)
if !ok { if f == nil {
return nil, fmt.Errorf(strings.TrimSpace(errBackendSavedUnknown), s.Backend.Type) return nil, fmt.Errorf(strings.TrimSpace(errBackendSavedUnknown), s.Backend.Type)
} }
b := f() b := f()
@ -1300,8 +1299,8 @@ func (m *Meta) backendInitFromConfig(c *config.Backend) (backend.Backend, error)
config := terraform.NewResourceConfig(c.RawConfig) config := terraform.NewResourceConfig(c.RawConfig)
// Get the backend // Get the backend
f, ok := Backends[c.Type] f := backendinit.Backend(c.Type)
if !ok { if f == nil {
return nil, fmt.Errorf(strings.TrimSpace(errBackendNewUnknown), c.Type) return nil, fmt.Errorf(strings.TrimSpace(errBackendNewUnknown), c.Type)
} }
b := f() b := f()
@ -1374,8 +1373,8 @@ func (m *Meta) backendInitFromSaved(s *terraform.BackendState) (backend.Backend,
config := terraform.NewResourceConfig(rawC) config := terraform.NewResourceConfig(rawC)
// Get the backend // Get the backend
f, ok := Backends[s.Type] f := backendinit.Backend(s.Type)
if !ok { if f == nil {
return nil, fmt.Errorf(strings.TrimSpace(errBackendSavedUnknown), s.Type) return nil, fmt.Errorf(strings.TrimSpace(errBackendSavedUnknown), s.Type)
} }
b := f() b := f()
@ -1397,27 +1396,6 @@ func (m *Meta) backendInitRequired(reason string) {
// Output constants and initialization code // 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 // errBackendInitRequired is the final error message shown when reinit
// is required for some reason. The error message includes the reason. // is required for some reason. The error message includes the reason.
var errBackendInitRequired = errors.New( var errBackendInitRequired = errors.New(