mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-23 23:50:12 -06:00
cb2e9119aa
Signed-off-by: namgyalangmo <75657887+namgyalangmo@users.noreply.github.com>
25 lines
807 B
Go
25 lines
807 B
Go
// Copyright (c) The OpenTofu Authors
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
// Copyright (c) 2023 HashiCorp, Inc.
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
package tofu
|
|
|
|
// updateStateHook calls the PostStateUpdate hook with the current state.
|
|
func updateStateHook(ctx EvalContext) error {
|
|
// In principle we could grab the lock here just long enough to take a
|
|
// deep copy and then pass that to our hooks below, but we'll instead
|
|
// hold the hook for the duration to avoid the potential confusing
|
|
// situation of us racing to call PostStateUpdate concurrently with
|
|
// different state snapshots.
|
|
stateSync := ctx.State()
|
|
state := stateSync.Lock().DeepCopy()
|
|
defer stateSync.Unlock()
|
|
|
|
// Call the hook
|
|
err := ctx.Hook(func(h Hook) (HookAction, error) {
|
|
return h.PostStateUpdate(state)
|
|
})
|
|
return err
|
|
}
|