github.com/KevinKlinger/open_terraform@v0.11.12-beta1/terraform/evaltree_provider.go (about)

     1  package terraform
     2  
     3  import (
     4  	"strings"
     5  
     6  	"github.com/hashicorp/terraform/config"
     7  )
     8  
     9  // ProviderEvalTree returns the evaluation tree for initializing and
    10  // configuring providers.
    11  func ProviderEvalTree(n *NodeApplyableProvider, config *config.ProviderConfig) EvalNode {
    12  	var provider ResourceProvider
    13  	var resourceConfig *ResourceConfig
    14  
    15  	typeName := strings.SplitN(n.NameValue, ".", 2)[0]
    16  
    17  	seq := make([]EvalNode, 0, 5)
    18  	seq = append(seq, &EvalInitProvider{
    19  		TypeName: typeName,
    20  		Name:     n.Name(),
    21  	})
    22  
    23  	// Input stuff
    24  	seq = append(seq, &EvalOpFilter{
    25  		Ops: []walkOperation{walkInput, walkImport},
    26  		Node: &EvalSequence{
    27  			Nodes: []EvalNode{
    28  				&EvalGetProvider{
    29  					Name:   n.Name(),
    30  					Output: &provider,
    31  				},
    32  				&EvalInterpolateProvider{
    33  					Config: config,
    34  					Output: &resourceConfig,
    35  				},
    36  				&EvalBuildProviderConfig{
    37  					Provider: n.NameValue,
    38  					Config:   &resourceConfig,
    39  					Output:   &resourceConfig,
    40  				},
    41  				&EvalInputProvider{
    42  					Name:     n.NameValue,
    43  					Provider: &provider,
    44  					Config:   &resourceConfig,
    45  				},
    46  			},
    47  		},
    48  	})
    49  
    50  	seq = append(seq, &EvalOpFilter{
    51  		Ops: []walkOperation{walkValidate},
    52  		Node: &EvalSequence{
    53  			Nodes: []EvalNode{
    54  				&EvalGetProvider{
    55  					Name:   n.Name(),
    56  					Output: &provider,
    57  				},
    58  				&EvalInterpolateProvider{
    59  					Config: config,
    60  					Output: &resourceConfig,
    61  				},
    62  				&EvalBuildProviderConfig{
    63  					Provider: n.NameValue,
    64  					Config:   &resourceConfig,
    65  					Output:   &resourceConfig,
    66  				},
    67  				&EvalValidateProvider{
    68  					Provider: &provider,
    69  					Config:   &resourceConfig,
    70  				},
    71  			},
    72  		},
    73  	})
    74  
    75  	// Apply stuff
    76  	seq = append(seq, &EvalOpFilter{
    77  		Ops: []walkOperation{walkRefresh, walkPlan, walkApply, walkDestroy, walkImport},
    78  		Node: &EvalSequence{
    79  			Nodes: []EvalNode{
    80  				&EvalGetProvider{
    81  					Name:   n.Name(),
    82  					Output: &provider,
    83  				},
    84  				&EvalInterpolateProvider{
    85  					Config: config,
    86  					Output: &resourceConfig,
    87  				},
    88  				&EvalBuildProviderConfig{
    89  					Provider: n.NameValue,
    90  					Config:   &resourceConfig,
    91  					Output:   &resourceConfig,
    92  				},
    93  			},
    94  		},
    95  	})
    96  
    97  	// We configure on everything but validate, since validate may
    98  	// not have access to all the variables.
    99  	seq = append(seq, &EvalOpFilter{
   100  		Ops: []walkOperation{walkRefresh, walkPlan, walkApply, walkDestroy, walkImport},
   101  		Node: &EvalSequence{
   102  			Nodes: []EvalNode{
   103  				&EvalConfigProvider{
   104  					Provider: n.Name(),
   105  					Config:   &resourceConfig,
   106  				},
   107  			},
   108  		},
   109  	})
   110  
   111  	return &EvalSequence{Nodes: seq}
   112  }
   113  
   114  // CloseProviderEvalTree returns the evaluation tree for closing
   115  // provider connections that aren't needed anymore.
   116  func CloseProviderEvalTree(n string) EvalNode {
   117  	return &EvalCloseProvider{Name: n}
   118  }