Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backend/local: disable local backup of remote state #16464

Merged
merged 1 commit into from
Oct 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 2 additions & 21 deletions backend/local/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,28 +180,9 @@ func (b *Local) DeleteState(name string) error {
func (b *Local) State(name string) (state.State, error) {
statePath, stateOutPath, backupPath := b.StatePaths(name)

// If we have a backend handling state, defer to that.
// If we have a backend handling state, delegate to that.
if b.Backend != nil {
s, err := b.Backend.State(name)
if err != nil {
return nil, err
}

// make sure we always have a backup state, unless it disabled
if backupPath == "" {
return s, nil
}

// see if the delegated backend returned a BackupState of its own
if s, ok := s.(*state.BackupState); ok {
return s, nil
}

s = &state.BackupState{
Real: s,
Path: backupPath,
}
return s, nil
return b.Backend.State(name)
}

if s, ok := b.states[name]; ok {
Expand Down
37 changes: 0 additions & 37 deletions backend/local/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,43 +229,6 @@ func TestLocal_multiStateBackend(t *testing.T) {
}
}

// verify that a remote state backend is always wrapped in a BackupState
func TestLocal_remoteStateBackup(t *testing.T) {
// assign a separate backend to mock a remote state backend
b := &Local{
Backend: &testDelegateBackend{},
}

s, err := b.State("default")
if err != nil {
t.Fatal(err)
}

bs, ok := s.(*state.BackupState)
if !ok {
t.Fatal("remote state is not backed up")
}

if bs.Path != DefaultStateFilename+DefaultBackupExtension {
t.Fatal("bad backup location:", bs.Path)
}

// do the same with a named state, which should use the local env directories
s, err = b.State("test")
if err != nil {
t.Fatal(err)
}

bs, ok = s.(*state.BackupState)
if !ok {
t.Fatal("remote state is not backed up")
}

if bs.Path != filepath.Join(DefaultWorkspaceDir, "test", DefaultStateFilename+DefaultBackupExtension) {
t.Fatal("bad backup location:", bs.Path)
}
}

// change into a tmp dir and return a deferable func to change back and cleanup
func testTmpDir(t *testing.T) func() {
tmp, err := ioutil.TempDir("", "tf")
Expand Down