terraform: destroy module plan

This commit is contained in:
Mitchell Hashimoto 2015-02-12 12:49:48 -08:00
parent e185769271
commit ec6ce69e90
3 changed files with 52 additions and 6 deletions

View File

@ -875,8 +875,7 @@ func TestContext2Plan_destroy(t *testing.T) {
}
}
/*
func TestContextPlan_moduleDestroy(t *testing.T) {
func TestContext2Plan_moduleDestroy(t *testing.T) {
m := testModule(t, "plan-module-destroy")
p := testProvider("aws")
p.DiffFn = testDiffFn
@ -906,7 +905,7 @@ func TestContextPlan_moduleDestroy(t *testing.T) {
},
},
}
ctx := testContext(t, &ContextOpts{
ctx := testContext2(t, &ContextOpts{
Module: m,
Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p),
@ -926,6 +925,7 @@ func TestContextPlan_moduleDestroy(t *testing.T) {
}
}
/*
func TestContextPlan_moduleDestroyMultivar(t *testing.T) {
m := testModule(t, "plan-module-destroy-multivar")
p := testProvider("aws")

View File

@ -151,6 +151,39 @@ func (n *EvalDiffDestroy) Type() EvalType {
return EvalTypeNull
}
// EvalDiffDestroyModule is an EvalNode implementation that writes the diff to
// the full diff.
type EvalDiffDestroyModule struct {
Path []string
}
func (n *EvalDiffDestroyModule) Args() ([]EvalNode, []EvalType) {
return nil, nil
}
// TODO: test
func (n *EvalDiffDestroyModule) Eval(
ctx EvalContext, args []interface{}) (interface{}, error) {
diff, lock := ctx.Diff()
// Acquire the lock so that we can do this safely concurrently
lock.Lock()
defer lock.Unlock()
// Write the diff
modDiff := diff.ModuleByPath(n.Path)
if modDiff == nil {
modDiff = diff.AddModule(n.Path)
}
modDiff.Destroy = true
return nil, nil
}
func (n *EvalDiffDestroyModule) Type() EvalType {
return EvalTypeNull
}
// EvalWriteDiff is an EvalNode implementation that writes the diff to
// the full diff.
type EvalWriteDiff struct {

View File

@ -306,9 +306,22 @@ func (n *graphNodeModuleExpanded) Name() string {
// GraphNodeEvalable impl.
func (n *graphNodeModuleExpanded) EvalTree() EvalNode {
return &EvalVariableBlock{
return &EvalSequence{
Nodes: []EvalNode{
&EvalVariableBlock{
Config: &EvalInterpolate{Config: n.InputConfig},
Variables: n.Variables,
},
&EvalOpFilter{
Ops: []walkOperation{walkPlanDestroy},
Node: &EvalSequence{
Nodes: []EvalNode{
&EvalDiffDestroyModule{Path: n.Graph.Path},
},
},
},
},
}
}