github.com/hugorut/terraform@v1.1.3/src/backend/local/hook_state.go (about)

     1  package local
     2  
     3  import (
     4  	"sync"
     5  
     6  	"github.com/hugorut/terraform/src/states"
     7  	"github.com/hugorut/terraform/src/states/statemgr"
     8  	"github.com/hugorut/terraform/src/terraform"
     9  )
    10  
    11  // StateHook is a hook that continuously updates the state by calling
    12  // WriteState on a statemgr.Full.
    13  type StateHook struct {
    14  	terraform.NilHook
    15  	sync.Mutex
    16  
    17  	StateMgr statemgr.Writer
    18  }
    19  
    20  var _ terraform.Hook = (*StateHook)(nil)
    21  
    22  func (h *StateHook) PostStateUpdate(new *states.State) (terraform.HookAction, error) {
    23  	h.Lock()
    24  	defer h.Unlock()
    25  
    26  	if h.StateMgr != nil {
    27  		if err := h.StateMgr.WriteState(new); err != nil {
    28  			return terraform.HookActionHalt, err
    29  		}
    30  	}
    31  
    32  	return terraform.HookActionContinue, nil
    33  }