diff --git a/command/state_meta.go b/command/state_meta.go index 7b6e136947..760119302e 100644 --- a/command/state_meta.go +++ b/command/state_meta.go @@ -28,7 +28,7 @@ func (c *StateMeta) State(m *Meta) (state.State, error) { // 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", + "%s.%d%s", m.stateOutPath, time.Now().UTC().Unix(), DefaultBackupExtension) diff --git a/command/state_test.go b/command/state_test.go index 7fe83e9049..b02fd964de 100644 --- a/command/state_test.go +++ b/command/state_test.go @@ -2,8 +2,11 @@ package command import ( "path/filepath" + "regexp" "sort" "testing" + + "github.com/hashicorp/terraform/state" ) // testStateBackups returns the list of backups in order of creation @@ -20,3 +23,16 @@ func testStateBackups(t *testing.T, dir string) []string { return list } + +func TestStateDefaultBackupExtension(t *testing.T) { + s, err := (&StateMeta{}).State(&Meta{}) + if err != nil { + t.Fatal(err) + } + + backupPath := s.(*state.BackupState).Path + match := regexp.MustCompile(`terraform\.tfstate\.\d+\.backup$`).MatchString + if !match(backupPath) { + t.Fatal("Bad backup path:", backupPath) + } +}