github.com/kanishk98/terraform@v1.3.0-dev.0.20220917174235-661ca8088a6a/internal/terraform/update_state_hook.go (about) 1 package terraform 2 3 // updateStateHook calls the PostStateUpdate hook with the current state. 4 func updateStateHook(ctx EvalContext) error { 5 // In principle we could grab the lock here just long enough to take a 6 // deep copy and then pass that to our hooks below, but we'll instead 7 // hold the hook for the duration to avoid the potential confusing 8 // situation of us racing to call PostStateUpdate concurrently with 9 // different state snapshots. 10 stateSync := ctx.State() 11 state := stateSync.Lock().DeepCopy() 12 defer stateSync.Unlock() 13 14 // Call the hook 15 err := ctx.Hook(func(h Hook) (HookAction, error) { 16 return h.PostStateUpdate(state) 17 }) 18 return err 19 }