opentofu/state
Martin Atkins 85eda8a059 state/remote: Don't persist snapshot for unchanged state
Previously we would write to the backend for every call to PersistState,
even if nothing changed since the last write, but update the serial only
if the state had changed.

The Terraform Cloud & Enterprise state storage have a simple safety check
that any future write with an already-used lineage and serial must be
byte-for-byte identical. StatesMarshalEqual is intended to detect that,
but it only actually detects changes the state itself, and not changes
to the snapshot metadata.

Because we write the current Terraform version into the snapshot metadata
during serialization, we'd previously have an issue where if the first
state write after upgrading Terraform to a new version happened to change
nothing about the state content then we'd write a new snapshot that
differed only by Terraform version, and Terraform Cloud/Enterprise would
then reject it.

The snapshot header is discarded immediately after decoding, so we can't
use information from it when deciding whether to increment the serial.
The next best thing is to skip sending no-op snapshot updates to the state
client in the first place.

These writes are unnecessary anyway, and state storage owners have asked
us in the past to elide these to avoid generating noise in their version
logs, so we'll also finally meet those requests as a nice side-effect of
this change.

We didn't previously have tests for the full flow of retrieving and then
successively updating persisted state snapshots, so this includes a test
which covers that logic and includes an assertion that a no-op update does
not get written to the state client.
2019-06-20 06:18:40 -07:00
..
remote state/remote: Don't persist snapshot for unchanged state 2019-06-20 06:18:40 -07:00
testdata Use NewLockInfo to get a pre-populated value 2017-02-15 14:41:55 -05:00
backup.go terraform: Ugly huge change to weave in new State and Plan types 2018-10-16 19:11:09 -07:00
inmem.go state: more robust handling of state Serial 2017-07-05 12:34:30 -07:00
local_lock_unix.go Use io.SeekStart instead of deprecated os.SEEK_SET 2018-02-25 23:11:40 +01:00
local_lock_windows.go fix windows locking 2017-02-17 13:29:48 -05:00
local.go Merge pull request #17431 from oscr/use-seekstart 2018-04-04 15:27:24 -04:00
lock_test.go backend/consul: support "lock" option to disable locking 2017-03-14 17:59:10 -07:00
lock.go terraform: Ugly huge change to weave in new State and Plan types 2018-10-16 19:11:09 -07:00
state_test.go state: Remove tests for obsolete components 2018-10-16 19:14:11 -07:00
state.go remove single rand source to prevent races 2019-02-21 20:45:41 -05:00
testing.go terraform: Ugly huge change to weave in new State and Plan types 2018-10-16 19:11:09 -07:00