terraform: PostApply should get error result from Apply

This commit is contained in:
Mitchell Hashimoto 2014-07-17 15:38:50 -07:00
parent ff36378c4e
commit 3276ae313f
5 changed files with 28 additions and 20 deletions

View File

@ -62,12 +62,16 @@ func (h *CountHook) PreApply(
func (h *CountHook) PostApply( func (h *CountHook) PostApply(
id string, id string,
s *terraform.ResourceState) (terraform.HookAction, error) { s *terraform.ResourceState,
e error) (terraform.HookAction, error) {
h.Lock() h.Lock()
defer h.Unlock() defer h.Unlock()
if h.pending != nil { if h.pending != nil {
if a, ok := h.pending[id]; ok { if a, ok := h.pending[id]; ok {
delete(h.pending, id)
if e == nil {
switch a { switch a {
case countHookActionAdd: case countHookActionAdd:
h.Added += 1 h.Added += 1
@ -78,6 +82,7 @@ func (h *CountHook) PostApply(
} }
} }
} }
}
return terraform.HookActionContinue, nil return terraform.HookActionContinue, nil
} }

View File

@ -547,7 +547,7 @@ func (c *Context) applyWalkFn() depgraph.WalkFunc {
r.State = rs r.State = rs
for _, h := range c.hooks { for _, h := range c.hooks {
handleHook(h.PostApply(r.Id, r.State)) handleHook(h.PostApply(r.Id, r.State, applyerr))
} }
// Determine the new state and update variables // Determine the new state and update variables

View File

@ -22,9 +22,10 @@ const (
// nothing. Then, override only the functions you want to implement. // nothing. Then, override only the functions you want to implement.
type Hook interface { type Hook interface {
// PreApply and PostApply are called before and after a single // PreApply and PostApply are called before and after a single
// resource is applied. // resource is applied. The error argument in PostApply is the
// error, if any, that was returned from the provider Apply call itself.
PreApply(string, *ResourceState, *ResourceDiff) (HookAction, error) PreApply(string, *ResourceState, *ResourceDiff) (HookAction, error)
PostApply(string, *ResourceState) (HookAction, error) PostApply(string, *ResourceState, error) (HookAction, error)
// PreDiff and PostDiff are called before and after a single resource // PreDiff and PostDiff are called before and after a single resource
// resource is diffed. // resource is diffed.
@ -46,7 +47,7 @@ func (*NilHook) PreApply(string, *ResourceState, *ResourceDiff) (HookAction, err
return HookActionContinue, nil return HookActionContinue, nil
} }
func (*NilHook) PostApply(string, *ResourceState) (HookAction, error) { func (*NilHook) PostApply(string, *ResourceState, error) (HookAction, error) {
return HookActionContinue, nil return HookActionContinue, nil
} }

View File

@ -13,8 +13,9 @@ type MockHook struct {
PostApplyCalled bool PostApplyCalled bool
PostApplyId string PostApplyId string
PostApplyState *ResourceState PostApplyState *ResourceState
PostApplyReturn HookAction
PostApplyError error PostApplyError error
PostApplyReturn HookAction
PostApplyReturnError error
PreDiffCalled bool PreDiffCalled bool
PreDiffId string PreDiffId string
@ -49,11 +50,12 @@ func (h *MockHook) PreApply(n string, s *ResourceState, d *ResourceDiff) (HookAc
return h.PreApplyReturn, h.PreApplyError return h.PreApplyReturn, h.PreApplyError
} }
func (h *MockHook) PostApply(n string, s *ResourceState) (HookAction, error) { func (h *MockHook) PostApply(n string, s *ResourceState, e error) (HookAction, error) {
h.PostApplyCalled = true h.PostApplyCalled = true
h.PostApplyId = n h.PostApplyId = n
h.PostApplyState = s h.PostApplyState = s
return h.PostApplyReturn, h.PostApplyError h.PostApplyError = e
return h.PostApplyReturn, h.PostApplyReturnError
} }
func (h *MockHook) PreDiff(n string, s *ResourceState) (HookAction, error) { func (h *MockHook) PreDiff(n string, s *ResourceState) (HookAction, error) {

View File

@ -14,7 +14,7 @@ func (h *stopHook) PreApply(string, *ResourceState, *ResourceDiff) (HookAction,
return h.hook() return h.hook()
} }
func (h *stopHook) PostApply(string, *ResourceState) (HookAction, error) { func (h *stopHook) PostApply(string, *ResourceState, error) (HookAction, error) {
return h.hook() return h.hook()
} }