]> git.immae.eu Git - github/fretlink/terraform-provider-statuscake.git/blob - vendor/github.com/hashicorp/terraform/terraform/hook_stop.go
Upgrade to 0.12
[github/fretlink/terraform-provider-statuscake.git] / vendor / github.com / hashicorp / terraform / terraform / hook_stop.go
1 package terraform
2
3 import (
4 "sync/atomic"
5
6 "github.com/zclconf/go-cty/cty"
7
8 "github.com/hashicorp/terraform/addrs"
9 "github.com/hashicorp/terraform/plans"
10 "github.com/hashicorp/terraform/providers"
11 "github.com/hashicorp/terraform/states"
12 )
13
14 // stopHook is a private Hook implementation that Terraform uses to
15 // signal when to stop or cancel actions.
16 type stopHook struct {
17 stop uint32
18 }
19
20 var _ Hook = (*stopHook)(nil)
21
22 func (h *stopHook) PreApply(addr addrs.AbsResourceInstance, gen states.Generation, action plans.Action, priorState, plannedNewState cty.Value) (HookAction, error) {
23 return h.hook()
24 }
25
26 func (h *stopHook) PostApply(addr addrs.AbsResourceInstance, gen states.Generation, newState cty.Value, err error) (HookAction, error) {
27 return h.hook()
28 }
29
30 func (h *stopHook) PreDiff(addr addrs.AbsResourceInstance, gen states.Generation, priorState, proposedNewState cty.Value) (HookAction, error) {
31 return h.hook()
32 }
33
34 func (h *stopHook) PostDiff(addr addrs.AbsResourceInstance, gen states.Generation, action plans.Action, priorState, plannedNewState cty.Value) (HookAction, error) {
35 return h.hook()
36 }
37
38 func (h *stopHook) PreProvisionInstance(addr addrs.AbsResourceInstance, state cty.Value) (HookAction, error) {
39 return h.hook()
40 }
41
42 func (h *stopHook) PostProvisionInstance(addr addrs.AbsResourceInstance, state cty.Value) (HookAction, error) {
43 return h.hook()
44 }
45
46 func (h *stopHook) PreProvisionInstanceStep(addr addrs.AbsResourceInstance, typeName string) (HookAction, error) {
47 return h.hook()
48 }
49
50 func (h *stopHook) PostProvisionInstanceStep(addr addrs.AbsResourceInstance, typeName string, err error) (HookAction, error) {
51 return h.hook()
52 }
53
54 func (h *stopHook) ProvisionOutput(addr addrs.AbsResourceInstance, typeName string, line string) {
55 }
56
57 func (h *stopHook) PreRefresh(addr addrs.AbsResourceInstance, gen states.Generation, priorState cty.Value) (HookAction, error) {
58 return h.hook()
59 }
60
61 func (h *stopHook) PostRefresh(addr addrs.AbsResourceInstance, gen states.Generation, priorState cty.Value, newState cty.Value) (HookAction, error) {
62 return h.hook()
63 }
64
65 func (h *stopHook) PreImportState(addr addrs.AbsResourceInstance, importID string) (HookAction, error) {
66 return h.hook()
67 }
68
69 func (h *stopHook) PostImportState(addr addrs.AbsResourceInstance, imported []providers.ImportedResource) (HookAction, error) {
70 return h.hook()
71 }
72
73 func (h *stopHook) PostStateUpdate(new *states.State) (HookAction, error) {
74 return h.hook()
75 }
76
77 func (h *stopHook) hook() (HookAction, error) {
78 if h.Stopped() {
79 // FIXME: This should really return an error since stopping partway
80 // through is not a successful run-to-completion, but we'll need to
81 // introduce that cautiously since existing automation solutions may
82 // be depending on this behavior.
83 return HookActionHalt, nil
84 }
85
86 return HookActionContinue, nil
87 }
88
89 // reset should be called within the lock context
90 func (h *stopHook) Reset() {
91 atomic.StoreUint32(&h.stop, 0)
92 }
93
94 func (h *stopHook) Stop() {
95 atomic.StoreUint32(&h.stop, 1)
96 }
97
98 func (h *stopHook) Stopped() bool {
99 return atomic.LoadUint32(&h.stop) == 1
100 }