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:
parent
dbc45b907c
commit
1ea9413c07
|
@ -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,
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue