diff --git a/terraform/eval_read_data.go b/terraform/eval_read_data.go index 62baa3c036..9625bcffae 100644 --- a/terraform/eval_read_data.go +++ b/terraform/eval_read_data.go @@ -80,6 +80,16 @@ func (n *EvalReadDataApply) Eval(ctx EvalContext) (interface{}, error) { provider := *n.Provider diff := *n.Diff + // If the diff is for *destroying* this resource then we'll + // just drop its state and move on, since data resources don't + // support an actual "destroy" action. + if diff.Destroy { + if n.Output != nil { + *n.Output = nil + } + return nil, nil + } + // For the purpose of external hooks we present a data apply as a // "Refresh" rather than an "Apply" because creating a data source // is presented to users/callers as a "read" operation. diff --git a/terraform/transform_resource.go b/terraform/transform_resource.go index 3150e4f2a2..da1471f874 100644 --- a/terraform/transform_resource.go +++ b/terraform/transform_resource.go @@ -735,6 +735,34 @@ func (n *graphNodeExpandedResource) dataResourceEvalNodes(resource *Resource, in }, }) + // Diff the resource for destruction + nodes = append(nodes, &EvalOpFilter{ + Ops: []walkOperation{walkPlanDestroy}, + Node: &EvalSequence{ + Nodes: []EvalNode{ + + &EvalReadState{ + Name: n.stateId(), + Output: &state, + }, + + // Since EvalDiffDestroy doesn't interact with the + // provider at all, we can safely share the same + // implementation for data vs. managed resources. + &EvalDiffDestroy{ + Info: info, + State: &state, + Output: &diff, + }, + + &EvalWriteDiff{ + Name: n.stateId(), + Diff: &diff, + }, + }, + }, + }) + // Apply nodes = append(nodes, &EvalOpFilter{ Ops: []walkOperation{walkApply, walkDestroy},