github.com/trawler/terraform@v0.10.8-0.20171106022149-4b1c7a1d9b48/terraform/node_resource_abstract_count.go (about)

     1  package terraform
     2  
     3  // NodeAbstractCountResource should be embedded instead of NodeAbstractResource
     4  // if the resource has a `count` value that needs to be expanded.
     5  //
     6  // The embedder should implement `DynamicExpand` to process the count.
     7  type NodeAbstractCountResource struct {
     8  	*NodeAbstractResource
     9  
    10  	// Validate, if true, will perform the validation for the count.
    11  	// This should only be turned on for the "validate" operation.
    12  	Validate bool
    13  }
    14  
    15  // GraphNodeEvalable
    16  func (n *NodeAbstractCountResource) EvalTree() EvalNode {
    17  	// We only check if the count is computed if we're not validating.
    18  	// If we're validating we allow computed counts since they just turn
    19  	// into more computed values.
    20  	var evalCountCheckComputed EvalNode
    21  	if !n.Validate {
    22  		evalCountCheckComputed = &EvalCountCheckComputed{Resource: n.Config}
    23  	}
    24  
    25  	return &EvalSequence{
    26  		Nodes: []EvalNode{
    27  			// The EvalTree for a plannable resource primarily involves
    28  			// interpolating the count since it can contain variables
    29  			// we only just received access to.
    30  			//
    31  			// With the interpolated count, we can then DynamicExpand
    32  			// into the proper number of instances.
    33  			&EvalInterpolate{Config: n.Config.RawCount},
    34  
    35  			// Check if the count is computed
    36  			evalCountCheckComputed,
    37  
    38  			// If validation is enabled, perform the validation
    39  			&EvalIf{
    40  				If: func(ctx EvalContext) (bool, error) {
    41  					return n.Validate, nil
    42  				},
    43  
    44  				Then: &EvalValidateCount{Resource: n.Config},
    45  			},
    46  
    47  			&EvalCountFixZeroOneBoundary{Resource: n.Config},
    48  		},
    49  	}
    50  }