github.com/turtlemonvh/terraform@v0.6.9-0.20151204001754-8e40b6b855e8/terraform/eval_check_prevent_destroy.go (about) 1 package terraform 2 3 import ( 4 "fmt" 5 6 "github.com/hashicorp/terraform/config" 7 ) 8 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 14 Diff **InstanceDiff 15 } 16 17 func (n *EvalCheckPreventDestroy) Eval(ctx EvalContext) (interface{}, error) { 18 if n.Diff == nil || *n.Diff == nil || n.Resource == nil { 19 return nil, nil 20 } 21 22 diff := *n.Diff 23 preventDestroy := n.Resource.Lifecycle.PreventDestroy 24 25 if diff.Destroy && preventDestroy { 26 return nil, fmt.Errorf(preventDestroyErrStr, n.Resource.Id()) 27 } 28 29 return nil, nil 30 } 31 32 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.`