github.com/wikibal01/hashicorp-terraform@v0.11.12-beta1/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, error) (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) PreImportState(*InstanceInfo, string) (HookAction, error) { 57 return h.hook() 58 } 59 60 func (h *stopHook) PostImportState(*InstanceInfo, []*InstanceState) (HookAction, error) { 61 return h.hook() 62 } 63 64 func (h *stopHook) PostStateUpdate(*State) (HookAction, error) { 65 return h.hook() 66 } 67 68 func (h *stopHook) hook() (HookAction, error) { 69 if h.Stopped() { 70 return HookActionHalt, nil 71 } 72 73 return HookActionContinue, nil 74 } 75 76 // reset should be called within the lock context 77 func (h *stopHook) Reset() { 78 atomic.StoreUint32(&h.stop, 0) 79 } 80 81 func (h *stopHook) Stop() { 82 atomic.StoreUint32(&h.stop, 1) 83 } 84 85 func (h *stopHook) Stopped() bool { 86 return atomic.LoadUint32(&h.stop) == 1 87 }