Merge pull request #9731 from hashicorp/b-deposed-hook
terraform: deposed should trigger PostApply hook
This commit is contained in:
commit
92abaf1905
|
@ -465,6 +465,65 @@ func TestContext2Apply_createBeforeDestroyUpdate(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestContext2Apply_createBeforeDestroy_hook(t *testing.T) {
|
||||||
|
h := new(MockHook)
|
||||||
|
m := testModule(t, "apply-good-create-before")
|
||||||
|
p := testProvider("aws")
|
||||||
|
p.ApplyFn = testApplyFn
|
||||||
|
p.DiffFn = testDiffFn
|
||||||
|
state := &State{
|
||||||
|
Modules: []*ModuleState{
|
||||||
|
&ModuleState{
|
||||||
|
Path: rootModulePath,
|
||||||
|
Resources: map[string]*ResourceState{
|
||||||
|
"aws_instance.bar": &ResourceState{
|
||||||
|
Type: "aws_instance",
|
||||||
|
Primary: &InstanceState{
|
||||||
|
ID: "bar",
|
||||||
|
Attributes: map[string]string{
|
||||||
|
"require_new": "abc",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
var actual []string
|
||||||
|
var actualLock sync.Mutex
|
||||||
|
h.PostApplyFn = func(n *InstanceInfo, s *InstanceState, e error) (HookAction, error) {
|
||||||
|
actualLock.Lock()
|
||||||
|
defer actualLock.Unlock()
|
||||||
|
actual = append(actual, n.Id)
|
||||||
|
return HookActionContinue, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx := testContext2(t, &ContextOpts{
|
||||||
|
Module: m,
|
||||||
|
Hooks: []Hook{h},
|
||||||
|
Providers: map[string]ResourceProviderFactory{
|
||||||
|
"aws": testProviderFuncFixed(p),
|
||||||
|
},
|
||||||
|
State: state,
|
||||||
|
})
|
||||||
|
|
||||||
|
if p, err := ctx.Plan(); err != nil {
|
||||||
|
t.Fatalf("err: %s", err)
|
||||||
|
} else {
|
||||||
|
t.Logf(p.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := ctx.Apply(); err != nil {
|
||||||
|
t.Fatalf("err: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
expected := []string{"aws_instance.bar", "aws_instance.bar (deposed #0)"}
|
||||||
|
if !reflect.DeepEqual(actual, expected) {
|
||||||
|
t.Fatalf("bad: %#v", actual)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestContext2Apply_destroyComputed(t *testing.T) {
|
func TestContext2Apply_destroyComputed(t *testing.T) {
|
||||||
m := testModule(t, "apply-destroy-computed")
|
m := testModule(t, "apply-destroy-computed")
|
||||||
p := testProvider("aws")
|
p := testProvider("aws")
|
||||||
|
|
|
@ -20,6 +20,7 @@ type MockHook struct {
|
||||||
PostApplyError error
|
PostApplyError error
|
||||||
PostApplyReturn HookAction
|
PostApplyReturn HookAction
|
||||||
PostApplyReturnError error
|
PostApplyReturnError error
|
||||||
|
PostApplyFn func(*InstanceInfo, *InstanceState, error) (HookAction, error)
|
||||||
|
|
||||||
PreDiffCalled bool
|
PreDiffCalled bool
|
||||||
PreDiffInfo *InstanceInfo
|
PreDiffInfo *InstanceInfo
|
||||||
|
@ -111,6 +112,11 @@ func (h *MockHook) PostApply(n *InstanceInfo, s *InstanceState, e error) (HookAc
|
||||||
h.PostApplyInfo = n
|
h.PostApplyInfo = n
|
||||||
h.PostApplyState = s
|
h.PostApplyState = s
|
||||||
h.PostApplyError = e
|
h.PostApplyError = e
|
||||||
|
|
||||||
|
if h.PostApplyFn != nil {
|
||||||
|
return h.PostApplyFn(n, s, e)
|
||||||
|
}
|
||||||
|
|
||||||
return h.PostApplyReturn, h.PostApplyReturnError
|
return h.PostApplyReturn, h.PostApplyReturnError
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -145,6 +145,11 @@ func (n *graphNodeDeposedResource) EvalTree() EvalNode {
|
||||||
State: &state,
|
State: &state,
|
||||||
Index: n.Index,
|
Index: n.Index,
|
||||||
},
|
},
|
||||||
|
&EvalApplyPost{
|
||||||
|
Info: info,
|
||||||
|
State: &state,
|
||||||
|
Error: &err,
|
||||||
|
},
|
||||||
&EvalReturnError{
|
&EvalReturnError{
|
||||||
Error: &err,
|
Error: &err,
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue