github.com/turtlemonvh/terraform@v0.6.9-0.20151204001754-8e40b6b855e8/terraform/hook_stop.go (about) 1 package terraform 2 3 import ( 4 "sync/atomic" 5 ) 6 7 // stopHook is a private Hook implementation that Terraform uses to 8 // signal when to stop or cancel actions. 9 type stopHook struct { 10 stop uint32 11 } 12 13 func (h *stopHook) PreApply(*InstanceInfo, *InstanceState, *InstanceDiff) (HookAction, error) { 14 return h.hook() 15 } 16 17 func (h *stopHook) PostApply(*InstanceInfo, *InstanceState, error) (HookAction, error) { 18 return h.hook() 19 } 20 21 func (h *stopHook) PreDiff(*InstanceInfo, *InstanceState) (HookAction, error) { 22 return h.hook() 23 } 24 25 func (h *stopHook) PostDiff(*InstanceInfo, *InstanceDiff) (HookAction, error) { 26 return h.hook() 27 } 28 29 func (h *stopHook) PreProvisionResource(*InstanceInfo, *InstanceState) (HookAction, error) { 30 return h.hook() 31 } 32 33 func (h *stopHook) PostProvisionResource(*InstanceInfo, *InstanceState) (HookAction, error) { 34 return h.hook() 35 } 36 37 func (h *stopHook) PreProvision(*InstanceInfo, string) (HookAction, error) { 38 return h.hook() 39 } 40 41 func (h *stopHook) PostProvision(*InstanceInfo, string) (HookAction, error) { 42 return h.hook() 43 } 44 45 func (h *stopHook) ProvisionOutput(*InstanceInfo, string, string) { 46 } 47 48 func (h *stopHook) PreRefresh(*InstanceInfo, *InstanceState) (HookAction, error) { 49 return h.hook() 50 } 51 52 func (h *stopHook) PostRefresh(*InstanceInfo, *InstanceState) (HookAction, error) { 53 return h.hook() 54 } 55 56 func (h *stopHook) PostStateUpdate(*State) (HookAction, error) { 57 return h.hook() 58 } 59 60 func (h *stopHook) hook() (HookAction, error) { 61 if h.Stopped() { 62 return HookActionHalt, nil 63 } 64 65 return HookActionContinue, nil 66 } 67 68 // reset should be called within the lock context 69 func (h *stopHook) Reset() { 70 atomic.StoreUint32(&h.stop, 0) 71 } 72 73 func (h *stopHook) Stop() { 74 atomic.StoreUint32(&h.stop, 1) 75 } 76 77 func (h *stopHook) Stopped() bool { 78 return atomic.LoadUint32(&h.stop) == 1 79 }