2020-12-07 14:39:20 +01:00
|
|
|
package terraform
|
|
|
|
|
2020-12-10 15:55:50 +01:00
|
|
|
// updateStateHook calls the PostStateUpdate hook with the current state.
|
|
|
|
func updateStateHook(ctx EvalContext) error {
|
2020-12-07 14:39:20 +01:00
|
|
|
// 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
|
|
|
|
}
|