opentofu/terraform/hook_stop.go

57 lines
1.1 KiB
Go
Raw Normal View History

2014-07-02 18:16:38 -05:00
package terraform
import (
2014-07-03 13:27:30 -05:00
"sync/atomic"
2014-07-02 18:16:38 -05:00
)
// stopHook is a private Hook implementation that Terraform uses to
// signal when to stop or cancel actions.
type stopHook struct {
2014-07-03 13:27:30 -05:00
stop uint32
2014-07-02 18:16:38 -05:00
}
func (h *stopHook) PreApply(string, *ResourceState, *ResourceDiff) (HookAction, error) {
return h.hook()
}
func (h *stopHook) PostApply(string, *ResourceState) (HookAction, error) {
return h.hook()
}
func (h *stopHook) PreDiff(string, *ResourceState) (HookAction, error) {
return h.hook()
}
func (h *stopHook) PostDiff(string, *ResourceDiff) (HookAction, error) {
return h.hook()
}
func (h *stopHook) PreRefresh(string, *ResourceState) (HookAction, error) {
return h.hook()
}
func (h *stopHook) PostRefresh(string, *ResourceState) (HookAction, error) {
return h.hook()
}
func (h *stopHook) hook() (HookAction, error) {
2014-07-03 13:27:30 -05:00
if h.Stopped() {
2014-07-02 18:16:38 -05:00
return HookActionHalt, nil
}
2014-07-03 13:27:30 -05:00
return HookActionContinue, nil
2014-07-02 18:16:38 -05:00
}
// reset should be called within the lock context
2014-07-03 13:27:30 -05:00
func (h *stopHook) Reset() {
atomic.StoreUint32(&h.stop, 0)
2014-07-02 18:16:38 -05:00
}
2014-07-03 13:27:30 -05:00
func (h *stopHook) Stop() {
atomic.StoreUint32(&h.stop, 1)
2014-07-02 18:16:38 -05:00
}
2014-07-03 13:27:30 -05:00
func (h *stopHook) Stopped() bool {
return atomic.LoadUint32(&h.stop) == 1
2014-07-02 18:16:38 -05:00
}