github.com/rhenning/terraform@v0.8.0-beta2/terraform/node_resource_plan_orphan.go (about)

     1  package terraform
     2  
     3  import (
     4  	"fmt"
     5  )
     6  
     7  // NodePlannableResourceOrphan represents a resource that is "applyable":
     8  // it is ready to be applied and is represented by a diff.
     9  type NodePlannableResourceOrphan struct {
    10  	*NodeAbstractResource
    11  }
    12  
    13  func (n *NodePlannableResourceOrphan) Name() string {
    14  	return n.NodeAbstractResource.Name() + " (orphan)"
    15  }
    16  
    17  // GraphNodeEvalable
    18  func (n *NodePlannableResourceOrphan) EvalTree() EvalNode {
    19  	addr := n.NodeAbstractResource.Addr
    20  
    21  	// stateId is the ID to put into the state
    22  	stateId := addr.stateId()
    23  	if addr.Index > -1 {
    24  		stateId = fmt.Sprintf("%s.%d", stateId, addr.Index)
    25  	}
    26  
    27  	// Build the instance info. More of this will be populated during eval
    28  	info := &InstanceInfo{
    29  		Id:         stateId,
    30  		Type:       addr.Type,
    31  		ModulePath: normalizeModulePath(addr.Path),
    32  	}
    33  
    34  	// Declare a bunch of variables that are used for state during
    35  	// evaluation. Most of this are written to by-address below.
    36  	var diff *InstanceDiff
    37  	var state *InstanceState
    38  
    39  	return &EvalSequence{
    40  		Nodes: []EvalNode{
    41  			&EvalReadState{
    42  				Name:   stateId,
    43  				Output: &state,
    44  			},
    45  			&EvalDiffDestroy{
    46  				Info:   info,
    47  				State:  &state,
    48  				Output: &diff,
    49  			},
    50  			&EvalCheckPreventDestroy{
    51  				Resource:   n.Config,
    52  				ResourceId: stateId,
    53  				Diff:       &diff,
    54  			},
    55  			&EvalWriteDiff{
    56  				Name: stateId,
    57  				Diff: &diff,
    58  			},
    59  		},
    60  	}
    61  }