diff --git a/command/meta_backend.go b/command/meta_backend.go index 86d7aaf7b..629fc9642 100644 --- a/command/meta_backend.go +++ b/command/meta_backend.go @@ -72,24 +72,6 @@ func (m *Meta) Backend(opts *BackendOpts) (backend.Enhanced, error) { opts = &BackendOpts{} } - // Setup the local state paths - statePath := m.statePath - stateOutPath := m.stateOutPath - backupPath := m.backupPath - if statePath == "" { - statePath = DefaultStateFilename - } - if stateOutPath == "" { - stateOutPath = statePath - } - if backupPath == "" { - backupPath = stateOutPath + DefaultBackupExtension - } - if backupPath == "-" { - // The local backend expects an empty string for not taking backups. - backupPath = "" - } - // Initialize a backend from the config unless we're forcing a purely // local operation. var b backend.Backend @@ -114,9 +96,9 @@ func (m *Meta) Backend(opts *BackendOpts) (backend.Enhanced, error) { cliOpts := &backend.CLIOpts{ CLI: m.Ui, CLIColor: m.Colorize(), - StatePath: statePath, - StateOutPath: stateOutPath, - StateBackupPath: backupPath, + StatePath: m.statePath, + StateOutPath: m.stateOutPath, + StateBackupPath: m.backupPath, ContextOpts: m.contextOpts(), Input: m.Input(), Validation: true, diff --git a/command/state_meta.go b/command/state_meta.go index 9155d0f95..eccfba447 100644 --- a/command/state_meta.go +++ b/command/state_meta.go @@ -36,12 +36,16 @@ func (c *StateMeta) State(m *Meta) (state.State, error) { panic(err) } localB := localRaw.(*backendlocal.Local) + _, stateOutPath, _, err := localB.StatePaths() + if err != nil { + return nil, err + } // Determine the backup path. stateOutPath is set to the resulting // file where state is written (cached in the case of remote state) backupPath := fmt.Sprintf( "%s.%d%s", - localB.StateOutPath, + stateOutPath, time.Now().UTC().Unix(), DefaultBackupExtension)