github.com/markdia/terraform@v0.5.1-0.20150508012022-f1ae920aa970/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: plan would destroy, but resource has prevent_destroy set. To avoid this error, either disable prevent_destroy, or change your config so the plan does not destroy this resource.`