Merge pull request #2506 from hashicorp/b-orphan-hook
terraform: orphans should call post-apply hook [GH-1938]
This commit is contained in:
commit
7daf13487f
|
@ -0,0 +1,16 @@
|
|||
// generated by stringer -type=countHookAction hook_count_action.go; DO NOT EDIT
|
||||
|
||||
package command
|
||||
|
||||
import "fmt"
|
||||
|
||||
const _countHookAction_name = "countHookActionAddcountHookActionChangecountHookActionRemove"
|
||||
|
||||
var _countHookAction_index = [...]uint8{0, 18, 39, 60}
|
||||
|
||||
func (i countHookAction) String() string {
|
||||
if i >= countHookAction(len(_countHookAction_index)-1) {
|
||||
return fmt.Sprintf("countHookAction(%d)", i)
|
||||
}
|
||||
return _countHookAction_name[_countHookAction_index[i]:_countHookAction_index[i+1]]
|
||||
}
|
|
@ -24,14 +24,6 @@ type CountHook struct {
|
|||
terraform.NilHook
|
||||
}
|
||||
|
||||
type countHookAction byte
|
||||
|
||||
const (
|
||||
countHookActionAdd countHookAction = iota
|
||||
countHookActionChange
|
||||
countHookActionRemove
|
||||
)
|
||||
|
||||
func (h *CountHook) Reset() {
|
||||
h.Lock()
|
||||
defer h.Unlock()
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
package command
|
||||
|
||||
//go:generate stringer -type=countHookAction hook_count_action.go
|
||||
|
||||
type countHookAction byte
|
||||
|
||||
const (
|
||||
countHookActionAdd countHookAction = iota
|
||||
countHookActionChange
|
||||
countHookActionRemove
|
||||
)
|
|
@ -5889,6 +5889,57 @@ func TestContext2Apply_hook(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestContext2Apply_hookOrphan(t *testing.T) {
|
||||
m := testModule(t, "apply-blank")
|
||||
h := new(MockHook)
|
||||
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",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Module: m,
|
||||
State: state,
|
||||
Hooks: []Hook{h},
|
||||
Providers: map[string]ResourceProviderFactory{
|
||||
"aws": testProviderFuncFixed(p),
|
||||
},
|
||||
})
|
||||
|
||||
if _, err := ctx.Plan(); err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
if _, err := ctx.Apply(); err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
if !h.PreApplyCalled {
|
||||
t.Fatal("should be called")
|
||||
}
|
||||
if !h.PostApplyCalled {
|
||||
t.Fatal("should be called")
|
||||
}
|
||||
if !h.PostStateUpdateCalled {
|
||||
t.Fatalf("should call post state update")
|
||||
}
|
||||
}
|
||||
|
||||
func TestContext2Apply_idAttr(t *testing.T) {
|
||||
m := testModule(t, "apply-idattr")
|
||||
p := testProvider("aws")
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
// Nothing!
|
|
@ -256,6 +256,7 @@ func (n *graphNodeOrphanResource) EvalTree() EvalNode {
|
|||
})
|
||||
|
||||
// Apply
|
||||
var err error
|
||||
seq.Nodes = append(seq.Nodes, &EvalOpFilter{
|
||||
Ops: []walkOperation{walkApply},
|
||||
Node: &EvalSequence{
|
||||
|
@ -278,6 +279,7 @@ func (n *graphNodeOrphanResource) EvalTree() EvalNode {
|
|||
Diff: &diff,
|
||||
Provider: &provider,
|
||||
Output: &state,
|
||||
Error: &err,
|
||||
},
|
||||
&EvalWriteState{
|
||||
Name: n.ResourceName,
|
||||
|
@ -286,6 +288,11 @@ func (n *graphNodeOrphanResource) EvalTree() EvalNode {
|
|||
Dependencies: n.DependentOn(),
|
||||
State: &state,
|
||||
},
|
||||
&EvalApplyPost{
|
||||
Info: info,
|
||||
State: &state,
|
||||
Error: &err,
|
||||
},
|
||||
&EvalUpdateStateHook{},
|
||||
},
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue