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