Remove state path handling from commands

The Local backend is now responsible for handling the paths to the local
state files, since they are dependent on the current environment.
This commit is contained in:
James Bardin 2017-02-22 13:11:26 -05:00
parent dbc45b907c
commit 1ea9413c07
2 changed files with 8 additions and 22 deletions

View File

@ -72,24 +72,6 @@ func (m *Meta) Backend(opts *BackendOpts) (backend.Enhanced, error) {
opts = &BackendOpts{} 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 // Initialize a backend from the config unless we're forcing a purely
// local operation. // local operation.
var b backend.Backend var b backend.Backend
@ -114,9 +96,9 @@ func (m *Meta) Backend(opts *BackendOpts) (backend.Enhanced, error) {
cliOpts := &backend.CLIOpts{ cliOpts := &backend.CLIOpts{
CLI: m.Ui, CLI: m.Ui,
CLIColor: m.Colorize(), CLIColor: m.Colorize(),
StatePath: statePath, StatePath: m.statePath,
StateOutPath: stateOutPath, StateOutPath: m.stateOutPath,
StateBackupPath: backupPath, StateBackupPath: m.backupPath,
ContextOpts: m.contextOpts(), ContextOpts: m.contextOpts(),
Input: m.Input(), Input: m.Input(),
Validation: true, Validation: true,

View File

@ -36,12 +36,16 @@ func (c *StateMeta) State(m *Meta) (state.State, error) {
panic(err) panic(err)
} }
localB := localRaw.(*backendlocal.Local) localB := localRaw.(*backendlocal.Local)
_, stateOutPath, _, err := localB.StatePaths()
if err != nil {
return nil, err
}
// Determine the backup path. stateOutPath is set to the resulting // Determine the backup path. stateOutPath is set to the resulting
// file where state is written (cached in the case of remote state) // file where state is written (cached in the case of remote state)
backupPath := fmt.Sprintf( backupPath := fmt.Sprintf(
"%s.%d%s", "%s.%d%s",
localB.StateOutPath, stateOutPath,
time.Now().UTC().Unix(), time.Now().UTC().Unix(),
DefaultBackupExtension) DefaultBackupExtension)