6 "github.com/hashicorp/terraform/config"
9 // EvalPreventDestroy is an EvalNode implementation that returns an
10 // error if a resource has PreventDestroy configured and the diff
11 // would destroy the resource.
12 type EvalCheckPreventDestroy struct {
13 Resource *config.Resource
18 func (n *EvalCheckPreventDestroy) Eval(ctx EvalContext) (interface{}, error) {
19 if n.Diff == nil || *n.Diff == nil || n.Resource == nil {
24 preventDestroy := n.Resource.Lifecycle.PreventDestroy
26 if diff.GetDestroy() && preventDestroy {
27 resourceId := n.ResourceId
29 resourceId = n.Resource.Id()
32 return nil, fmt.Errorf(preventDestroyErrStr, resourceId)
38 const preventDestroyErrStr = `%s: the plan would destroy this resource, but it currently has lifecycle.prevent_destroy set to true. To avoid this error and continue with the plan, either disable lifecycle.prevent_destroy or adjust the scope of the plan using the -target flag.`