github.com/hs0210/hashicorp-terraform@v0.11.12-beta1/backend/local/hook_state.go (about) 1 package local 2 3 import ( 4 "sync" 5 6 "github.com/hashicorp/terraform/state" 7 "github.com/hashicorp/terraform/terraform" 8 ) 9 10 // StateHook is a hook that continuously updates the state by calling 11 // WriteState on a state.State. 12 type StateHook struct { 13 terraform.NilHook 14 sync.Mutex 15 16 State state.State 17 } 18 19 func (h *StateHook) PostStateUpdate( 20 s *terraform.State) (terraform.HookAction, error) { 21 h.Lock() 22 defer h.Unlock() 23 24 if h.State != nil { 25 // Write the new state 26 if err := h.State.WriteState(s); err != nil { 27 return terraform.HookActionHalt, err 28 } 29 } 30 31 // Continue forth 32 return terraform.HookActionContinue, nil 33 }