mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-16 03:32:54 -06:00
6621501ae3
Most of the state package has been deprecated by the states package. This PR replaces all the references to the old state package that can be done simply - the low-hanging fruit. * states: move state.Locker to statemgr The state.Locker interface was a wrapper around a statemgr.Full, so moving this was relatively straightforward. * command: remove unnecessary use of state package for writing local terraform state files * move state.LocalState into terraform package state.LocalState is responsible for managing terraform.States, so it made sense (to me) to move it into the terraform package. * slight change of heart: move state.LocalState into clistate instead of terraform
34 lines
687 B
Go
34 lines
687 B
Go
package local
|
|
|
|
import (
|
|
"sync"
|
|
|
|
"github.com/hashicorp/terraform/states"
|
|
"github.com/hashicorp/terraform/states/statemgr"
|
|
"github.com/hashicorp/terraform/terraform"
|
|
)
|
|
|
|
// StateHook is a hook that continuously updates the state by calling
|
|
// WriteState on a statemgr.Full.
|
|
type StateHook struct {
|
|
terraform.NilHook
|
|
sync.Mutex
|
|
|
|
StateMgr statemgr.Writer
|
|
}
|
|
|
|
var _ terraform.Hook = (*StateHook)(nil)
|
|
|
|
func (h *StateHook) PostStateUpdate(new *states.State) (terraform.HookAction, error) {
|
|
h.Lock()
|
|
defer h.Unlock()
|
|
|
|
if h.StateMgr != nil {
|
|
if err := h.StateMgr.WriteState(new); err != nil {
|
|
return terraform.HookActionHalt, err
|
|
}
|
|
}
|
|
|
|
return terraform.HookActionContinue, nil
|
|
}
|