terraform/terraform/hook_stop.go

88 lines
2.0 KiB
Go
Raw Normal View History

2014-07-03 01:16:38 +02:00
package terraform
import (
2014-07-03 20:27:30 +02:00
"sync/atomic"
2014-07-03 01:16:38 +02:00
)
// stopHook is a private Hook implementation that Terraform uses to
// signal when to stop or cancel actions.
type stopHook struct {
2014-07-03 20:27:30 +02:00
stop uint32
2014-07-03 01:16:38 +02:00
}
func (h *stopHook) PreApply(*InstanceInfo, *InstanceState, *InstanceDiff) (HookAction, error) {
2014-07-03 01:16:38 +02:00
return h.hook()
}
func (h *stopHook) PostApply(*InstanceInfo, *InstanceState, error) (HookAction, error) {
2014-07-03 01:16:38 +02:00
return h.hook()
}
func (h *stopHook) PreDiff(*InstanceInfo, *InstanceState) (HookAction, error) {
2014-07-03 01:16:38 +02:00
return h.hook()
}
func (h *stopHook) PostDiff(*InstanceInfo, *InstanceDiff) (HookAction, error) {
2014-07-03 01:16:38 +02:00
return h.hook()
}
func (h *stopHook) PreProvisionResource(*InstanceInfo, *InstanceState) (HookAction, error) {
2014-07-27 18:00:34 +02:00
return h.hook()
}
func (h *stopHook) PostProvisionResource(*InstanceInfo, *InstanceState) (HookAction, error) {
2014-07-27 18:00:34 +02:00
return h.hook()
}
func (h *stopHook) PreProvision(*InstanceInfo, string) (HookAction, error) {
2014-07-27 18:00:34 +02:00
return h.hook()
}
func (h *stopHook) PostProvision(*InstanceInfo, string, error) (HookAction, error) {
2014-07-27 18:00:34 +02:00
return h.hook()
}
func (h *stopHook) ProvisionOutput(*InstanceInfo, string, string) {
}
func (h *stopHook) PreRefresh(*InstanceInfo, *InstanceState) (HookAction, error) {
2014-07-03 01:16:38 +02:00
return h.hook()
}
func (h *stopHook) PostRefresh(*InstanceInfo, *InstanceState) (HookAction, error) {
2014-07-03 01:16:38 +02:00
return h.hook()
}
func (h *stopHook) PreImportState(*InstanceInfo, string) (HookAction, error) {
return h.hook()
}
func (h *stopHook) PostImportState(*InstanceInfo, []*InstanceState) (HookAction, error) {
return h.hook()
}
func (h *stopHook) PostStateUpdate(*State) (HookAction, error) {
return h.hook()
}
2014-07-03 01:16:38 +02:00
func (h *stopHook) hook() (HookAction, error) {
2014-07-03 20:27:30 +02:00
if h.Stopped() {
2014-07-03 01:16:38 +02:00
return HookActionHalt, nil
}
2014-07-03 20:27:30 +02:00
return HookActionContinue, nil
2014-07-03 01:16:38 +02:00
}
// reset should be called within the lock context
2014-07-03 20:27:30 +02:00
func (h *stopHook) Reset() {
atomic.StoreUint32(&h.stop, 0)
2014-07-03 01:16:38 +02:00
}
2014-07-03 20:27:30 +02:00
func (h *stopHook) Stop() {
atomic.StoreUint32(&h.stop, 1)
2014-07-03 01:16:38 +02:00
}
2014-07-03 20:27:30 +02:00
func (h *stopHook) Stopped() bool {
return atomic.LoadUint32(&h.stop) == 1
2014-07-03 01:16:38 +02:00
}