diff --git a/terraform/context_test.go b/terraform/context_test.go index 3e4428772..44e00bf0b 100644 --- a/terraform/context_test.go +++ b/terraform/context_test.go @@ -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") diff --git a/terraform/eval_diff.go b/terraform/eval_diff.go index 2acccdc56..f2cd3590c 100644 --- a/terraform/eval_diff.go +++ b/terraform/eval_diff.go @@ -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 { diff --git a/terraform/graph_config_node.go b/terraform/graph_config_node.go index 07ff91b49..94880208e 100644 --- a/terraform/graph_config_node.go +++ b/terraform/graph_config_node.go @@ -306,9 +306,22 @@ func (n *graphNodeModuleExpanded) Name() string { // GraphNodeEvalable impl. func (n *graphNodeModuleExpanded) EvalTree() EvalNode { - return &EvalVariableBlock{ - Config: &EvalInterpolate{Config: n.InputConfig}, - Variables: n.Variables, + 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}, + }, + }, + }, + }, } }