github.com/serbaut/terraform@v0.6.12-0.20160607213102-ac2d195cc560/terraform/graph_config_node_output.go (about)

     1  package terraform
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/hashicorp/terraform/config"
     7  	"github.com/hashicorp/terraform/dag"
     8  )
     9  
    10  // GraphNodeConfigOutput represents an output configured within the
    11  // configuration.
    12  type GraphNodeConfigOutput struct {
    13  	Output *config.Output
    14  }
    15  
    16  func (n *GraphNodeConfigOutput) Name() string {
    17  	return fmt.Sprintf("output.%s", n.Output.Name)
    18  }
    19  
    20  func (n *GraphNodeConfigOutput) ConfigType() GraphNodeConfigType {
    21  	return GraphNodeConfigTypeOutput
    22  }
    23  
    24  func (n *GraphNodeConfigOutput) OutputName() string {
    25  	return n.Output.Name
    26  }
    27  
    28  func (n *GraphNodeConfigOutput) DependableName() []string {
    29  	return []string{n.Name()}
    30  }
    31  
    32  func (n *GraphNodeConfigOutput) DependentOn() []string {
    33  	vars := n.Output.RawConfig.Variables
    34  	result := make([]string, 0, len(vars))
    35  	for _, v := range vars {
    36  		if vn := varNameForVar(v); vn != "" {
    37  			result = append(result, vn)
    38  		}
    39  	}
    40  
    41  	return result
    42  }
    43  
    44  // GraphNodeEvalable impl.
    45  func (n *GraphNodeConfigOutput) EvalTree() EvalNode {
    46  	return &EvalOpFilter{
    47  		Ops: []walkOperation{walkRefresh, walkPlan, walkApply,
    48  			walkDestroy, walkInput, walkValidate},
    49  		Node: &EvalSequence{
    50  			Nodes: []EvalNode{
    51  				&EvalWriteOutput{
    52  					Name:      n.Output.Name,
    53  					Sensitive: n.Output.Sensitive,
    54  					Value:     n.Output.RawConfig,
    55  				},
    56  			},
    57  		},
    58  	}
    59  }
    60  
    61  // GraphNodeProxy impl.
    62  func (n *GraphNodeConfigOutput) Proxy() bool {
    63  	return true
    64  }
    65  
    66  // GraphNodeDestroyEdgeInclude impl.
    67  func (n *GraphNodeConfigOutput) DestroyEdgeInclude(dag.Vertex) bool {
    68  	return false
    69  }
    70  
    71  // GraphNodeFlattenable impl.
    72  func (n *GraphNodeConfigOutput) Flatten(p []string) (dag.Vertex, error) {
    73  	return &GraphNodeConfigOutputFlat{
    74  		GraphNodeConfigOutput: n,
    75  		PathValue:             p,
    76  	}, nil
    77  }
    78  
    79  // Same as GraphNodeConfigOutput, but for flattening
    80  type GraphNodeConfigOutputFlat struct {
    81  	*GraphNodeConfigOutput
    82  
    83  	PathValue []string
    84  }
    85  
    86  func (n *GraphNodeConfigOutputFlat) Name() string {
    87  	return fmt.Sprintf(
    88  		"%s.%s", modulePrefixStr(n.PathValue), n.GraphNodeConfigOutput.Name())
    89  }
    90  
    91  func (n *GraphNodeConfigOutputFlat) Path() []string {
    92  	return n.PathValue
    93  }
    94  
    95  func (n *GraphNodeConfigOutputFlat) DependableName() []string {
    96  	return modulePrefixList(
    97  		n.GraphNodeConfigOutput.DependableName(),
    98  		modulePrefixStr(n.PathValue))
    99  }
   100  
   101  func (n *GraphNodeConfigOutputFlat) DependentOn() []string {
   102  	prefix := modulePrefixStr(n.PathValue)
   103  	return modulePrefixList(
   104  		n.GraphNodeConfigOutput.DependentOn(),
   105  		prefix)
   106  }