terraform: PostApply should get error result from Apply
This commit is contained in:
parent
ff36378c4e
commit
3276ae313f
|
@ -62,12 +62,16 @@ func (h *CountHook) PreApply(
|
|||
|
||||
func (h *CountHook) PostApply(
|
||||
id string,
|
||||
s *terraform.ResourceState) (terraform.HookAction, error) {
|
||||
s *terraform.ResourceState,
|
||||
e error) (terraform.HookAction, error) {
|
||||
h.Lock()
|
||||
defer h.Unlock()
|
||||
|
||||
if h.pending != nil {
|
||||
if a, ok := h.pending[id]; ok {
|
||||
delete(h.pending, id)
|
||||
|
||||
if e == nil {
|
||||
switch a {
|
||||
case countHookActionAdd:
|
||||
h.Added += 1
|
||||
|
@ -78,6 +82,7 @@ func (h *CountHook) PostApply(
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return terraform.HookActionContinue, nil
|
||||
}
|
||||
|
|
|
@ -547,7 +547,7 @@ func (c *Context) applyWalkFn() depgraph.WalkFunc {
|
|||
r.State = rs
|
||||
|
||||
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
|
||||
|
|
|
@ -22,9 +22,10 @@ const (
|
|||
// nothing. Then, override only the functions you want to implement.
|
||||
type Hook interface {
|
||||
// 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)
|
||||
PostApply(string, *ResourceState) (HookAction, error)
|
||||
PostApply(string, *ResourceState, error) (HookAction, error)
|
||||
|
||||
// PreDiff and PostDiff are called before and after a single resource
|
||||
// resource is diffed.
|
||||
|
@ -46,7 +47,7 @@ func (*NilHook) PreApply(string, *ResourceState, *ResourceDiff) (HookAction, err
|
|||
return HookActionContinue, nil
|
||||
}
|
||||
|
||||
func (*NilHook) PostApply(string, *ResourceState) (HookAction, error) {
|
||||
func (*NilHook) PostApply(string, *ResourceState, error) (HookAction, error) {
|
||||
return HookActionContinue, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -13,8 +13,9 @@ type MockHook struct {
|
|||
PostApplyCalled bool
|
||||
PostApplyId string
|
||||
PostApplyState *ResourceState
|
||||
PostApplyReturn HookAction
|
||||
PostApplyError error
|
||||
PostApplyReturn HookAction
|
||||
PostApplyReturnError error
|
||||
|
||||
PreDiffCalled bool
|
||||
PreDiffId string
|
||||
|
@ -49,11 +50,12 @@ func (h *MockHook) PreApply(n string, s *ResourceState, d *ResourceDiff) (HookAc
|
|||
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.PostApplyId = n
|
||||
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) {
|
||||
|
|
|
@ -14,7 +14,7 @@ func (h *stopHook) PreApply(string, *ResourceState, *ResourceDiff) (HookAction,
|
|||
return h.hook()
|
||||
}
|
||||
|
||||
func (h *stopHook) PostApply(string, *ResourceState) (HookAction, error) {
|
||||
func (h *stopHook) PostApply(string, *ResourceState, error) (HookAction, error) {
|
||||
return h.hook()
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue