mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
Begin cloud remote state with serial > 0
This commit is contained in:
parent
afcbff193b
commit
de7304cacb
@ -140,6 +140,9 @@ func (s *State) PersistState(schemas *terraform.Schemas) error {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
|
||||
log.Printf("[DEBUG] cloud/state: state read serial is: %d; serial is: %d", s.readSerial, s.serial)
|
||||
log.Printf("[DEBUG] cloud/state: state read lineage is: %s; lineage is: %s", s.readLineage, s.lineage)
|
||||
|
||||
if s.readState != nil {
|
||||
lineageUnchanged := s.readLineage != "" && s.lineage == s.readLineage
|
||||
serialUnchanged := s.readSerial != 0 && s.serial == s.readSerial
|
||||
@ -157,13 +160,16 @@ func (s *State) PersistState(schemas *terraform.Schemas) error {
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed checking for existing remote state: %s", err)
|
||||
}
|
||||
log.Printf("[DEBUG] cloud/state: after refresh, state read serial is: %d; serial is: %d", s.readSerial, s.serial)
|
||||
log.Printf("[DEBUG] cloud/state: after refresh, state read lineage is: %s; lineage is: %s", s.readLineage, s.lineage)
|
||||
|
||||
if s.lineage == "" { // indicates that no state snapshot is present yet
|
||||
lineage, err := uuid.GenerateUUID()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to generate initial lineage: %v", err)
|
||||
}
|
||||
s.lineage = lineage
|
||||
s.serial = 0
|
||||
s.serial++
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -250,3 +250,23 @@ func TestDelete_SafeDelete(t *testing.T) {
|
||||
t.Fatalf("workspace %s not deleted", workspaceId)
|
||||
}
|
||||
}
|
||||
|
||||
func TestState_PersistState(t *testing.T) {
|
||||
cloudState := testCloudState(t)
|
||||
|
||||
t.Run("Initial PersistState", func(t *testing.T) {
|
||||
if cloudState.readState != nil {
|
||||
t.Fatal("expected nil initial readState")
|
||||
}
|
||||
|
||||
err := cloudState.PersistState(nil)
|
||||
if err != nil {
|
||||
t.Fatalf("expected no error, got %q", err)
|
||||
}
|
||||
|
||||
var expectedSerial uint64 = 1
|
||||
if cloudState.readSerial != expectedSerial {
|
||||
t.Fatalf("expected initial state readSerial to be %d, got %d", expectedSerial, cloudState.readSerial)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user