mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-28 17:34:24 -06:00
a42ebe389c
This reverts commit b73d037761
.
This commit seems to have introduced a race condition where we can
concurrently keep updating state after we've checked if we need to
increase the serial, and thus end up writing partial changes
to the state backend.
In the case of Terraform Enterprise, this fails altogether because
of the state hash consistency check it does.
34 lines
624 B
Go
34 lines
624 B
Go
package local
|
|
|
|
import (
|
|
"sync"
|
|
|
|
"github.com/hashicorp/terraform/state"
|
|
"github.com/hashicorp/terraform/terraform"
|
|
)
|
|
|
|
// StateHook is a hook that continuously updates the state by calling
|
|
// WriteState on a state.State.
|
|
type StateHook struct {
|
|
terraform.NilHook
|
|
sync.Mutex
|
|
|
|
State state.State
|
|
}
|
|
|
|
func (h *StateHook) PostStateUpdate(
|
|
s *terraform.State) (terraform.HookAction, error) {
|
|
h.Lock()
|
|
defer h.Unlock()
|
|
|
|
if h.State != nil {
|
|
// Write the new state
|
|
if err := h.State.WriteState(s); err != nil {
|
|
return terraform.HookActionHalt, err
|
|
}
|
|
}
|
|
|
|
// Continue forth
|
|
return terraform.HookActionContinue, nil
|
|
}
|