mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-19 21:22:57 -06:00
47a16b0937
a large refactor to addrs.AbsProviderConfig, embedding the addrs.Provider instead of a Type string. I've added and updated tests, added some Legacy functions to support older state formats and shims, and added a normalization step when reading v4 (current) state files (not the added tests under states/statefile/roundtrip which work with both current and legacy-style AbsProviderConfig strings). The remaining 'fixme' and 'todo' comments are mostly going to be addressed in a subsequent PR and involve looking up a given local provider config's FQN. This is fine for now as we are only working with default assumption.
90 lines
2.0 KiB
Go
90 lines
2.0 KiB
Go
package terraform
|
|
|
|
import (
|
|
"github.com/hashicorp/terraform/addrs"
|
|
"github.com/hashicorp/terraform/configs"
|
|
"github.com/hashicorp/terraform/providers"
|
|
)
|
|
|
|
// ProviderEvalTree returns the evaluation tree for initializing and
|
|
// configuring providers.
|
|
func ProviderEvalTree(n *NodeApplyableProvider, config *configs.Provider) EvalNode {
|
|
var provider providers.Interface
|
|
|
|
addr := n.Addr
|
|
|
|
seq := make([]EvalNode, 0, 5)
|
|
seq = append(seq, &EvalInitProvider{
|
|
// FIXME: type is now in the AbsProviderConfig, EvalInitProvider doen't
|
|
// need this field anymore
|
|
TypeName: addr.Provider.Type,
|
|
Addr: addr,
|
|
})
|
|
|
|
// Input stuff
|
|
seq = append(seq, &EvalOpFilter{
|
|
Ops: []walkOperation{walkImport},
|
|
Node: &EvalSequence{
|
|
Nodes: []EvalNode{
|
|
&EvalGetProvider{
|
|
Addr: addr,
|
|
Output: &provider,
|
|
},
|
|
},
|
|
},
|
|
})
|
|
|
|
seq = append(seq, &EvalOpFilter{
|
|
Ops: []walkOperation{walkValidate},
|
|
Node: &EvalSequence{
|
|
Nodes: []EvalNode{
|
|
&EvalGetProvider{
|
|
Addr: addr,
|
|
Output: &provider,
|
|
},
|
|
&EvalValidateProvider{
|
|
Addr: addr,
|
|
Provider: &provider,
|
|
Config: config,
|
|
},
|
|
},
|
|
},
|
|
})
|
|
|
|
// Apply stuff
|
|
seq = append(seq, &EvalOpFilter{
|
|
Ops: []walkOperation{walkRefresh, walkPlan, walkApply, walkDestroy, walkImport},
|
|
Node: &EvalSequence{
|
|
Nodes: []EvalNode{
|
|
&EvalGetProvider{
|
|
Addr: addr,
|
|
Output: &provider,
|
|
},
|
|
},
|
|
},
|
|
})
|
|
|
|
// 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{
|
|
&EvalConfigProvider{
|
|
Addr: addr,
|
|
Provider: &provider,
|
|
Config: config,
|
|
},
|
|
},
|
|
},
|
|
})
|
|
|
|
return &EvalSequence{Nodes: seq}
|
|
}
|
|
|
|
// CloseProviderEvalTree returns the evaluation tree for closing
|
|
// provider connections that aren't needed anymore.
|
|
func CloseProviderEvalTree(addr addrs.AbsProviderConfig) EvalNode {
|
|
return &EvalCloseProvider{Addr: addr}
|
|
}
|