opentofu/terraform/evaltree_provider.go

120 lines
2.6 KiB
Go
Raw Normal View History

package terraform
import (
"github.com/hashicorp/terraform/config"
)
// ProviderEvalTree returns the evaluation tree for initializing and
// configuring providers.
func ProviderEvalTree(n string, config *config.RawConfig) EvalNode {
2015-02-14 00:58:41 -06:00
var provider ResourceProvider
var resourceConfig *ResourceConfig
2015-02-13 19:59:54 -06:00
seq := make([]EvalNode, 0, 5)
seq = append(seq, &EvalInitProvider{Name: n})
// Input stuff
seq = append(seq, &EvalOpFilter{
Ops: []walkOperation{walkInput, walkImport},
2015-02-13 19:59:54 -06:00
Node: &EvalSequence{
Nodes: []EvalNode{
&EvalGetProvider{
Name: n,
Output: &provider,
},
&EvalInterpolate{
Config: config,
Output: &resourceConfig,
},
&EvalBuildProviderConfig{
Provider: n,
Config: &resourceConfig,
Output: &resourceConfig,
},
2015-02-13 19:59:54 -06:00
&EvalInputProvider{
Name: n,
Provider: &provider,
Config: &resourceConfig,
2015-02-13 19:59:54 -06:00
},
},
2015-02-13 19:59:54 -06:00
},
})
seq = append(seq, &EvalOpFilter{
Ops: []walkOperation{walkValidate},
2015-02-13 19:59:54 -06:00
Node: &EvalSequence{
Nodes: []EvalNode{
2015-02-14 00:58:41 -06:00
&EvalGetProvider{
Name: n,
Output: &provider,
},
&EvalInterpolate{
Config: config,
Output: &resourceConfig,
},
&EvalBuildProviderConfig{
Provider: n,
Config: &resourceConfig,
Output: &resourceConfig,
},
2015-02-13 19:59:54 -06:00
&EvalValidateProvider{
Provider: &provider,
Config: &resourceConfig,
2015-02-13 19:59:54 -06:00
},
&EvalSetProviderConfig{
Provider: n,
Config: &resourceConfig,
},
},
},
})
// Apply stuff
seq = append(seq, &EvalOpFilter{
Ops: []walkOperation{walkRefresh, walkPlan, walkApply, walkDestroy, walkImport},
Node: &EvalSequence{
Nodes: []EvalNode{
&EvalGetProvider{
Name: n,
Output: &provider,
},
&EvalInterpolate{
Config: config,
Output: &resourceConfig,
},
&EvalBuildProviderConfig{
Provider: n,
Config: &resourceConfig,
Output: &resourceConfig,
},
&EvalSetProviderConfig{
Provider: n,
Config: &resourceConfig,
},
},
},
})
// We configure on everything but validate, since validate may
// not have access to all the variables.
seq = append(seq, &EvalOpFilter{
Ops: []walkOperation{walkRefresh, walkPlan, walkApply, walkDestroy, walkImport},
Node: &EvalSequence{
Nodes: []EvalNode{
2015-02-13 19:59:54 -06:00
&EvalConfigProvider{
Provider: n,
2015-02-14 00:58:41 -06:00
Config: &resourceConfig,
2015-02-13 19:59:54 -06:00
},
},
},
2015-02-13 19:59:54 -06:00
})
return &EvalSequence{Nodes: seq}
}
// CloseProviderEvalTree returns the evaluation tree for closing
// provider connections that aren't needed anymore.
func CloseProviderEvalTree(n string) EvalNode {
return &EvalCloseProvider{Name: n}
}