Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

terraform: orphans should call post-apply hook [GH-1938] #2506

Merged
merged 1 commit into from
Jun 26, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions command/counthookaction_string.go
Original file line number Diff line number Diff line change
@@ -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]]
}
8 changes: 0 additions & 8 deletions command/hook_count.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
11 changes: 11 additions & 0 deletions command/hook_count_action.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package command

//go:generate stringer -type=countHookAction hook_count_action.go

type countHookAction byte

const (
countHookActionAdd countHookAction = iota
countHookActionChange
countHookActionRemove
)
51 changes: 51 additions & 0 deletions terraform/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5912,6 +5912,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")
Expand Down
1 change: 1 addition & 0 deletions terraform/test-fixtures/apply-blank/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Nothing!
7 changes: 7 additions & 0 deletions terraform/transform_orphan.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ func (n *graphNodeOrphanResource) EvalTree() EvalNode {
})

// Apply
var err error
seq.Nodes = append(seq.Nodes, &EvalOpFilter{
Ops: []walkOperation{walkApply},
Node: &EvalSequence{
Expand All @@ -278,6 +279,7 @@ func (n *graphNodeOrphanResource) EvalTree() EvalNode {
Diff: &diff,
Provider: &provider,
Output: &state,
Error: &err,
},
&EvalWriteState{
Name: n.ResourceName,
Expand All @@ -286,6 +288,11 @@ func (n *graphNodeOrphanResource) EvalTree() EvalNode {
Dependencies: n.DependentOn(),
State: &state,
},
&EvalApplyPost{
Info: info,
State: &state,
Error: &err,
},
&EvalUpdateStateHook{},
},
},
Expand Down