mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-30 10:47:14 -06:00
0b1dbf31a3
Currently Terraform is leaking goroutines and with that memory. I know strictly speaking this maybe isn’t a real concern for Terraform as it’s mostly used as a short running command line executable. But there are a few of us out there that are using Terraform in some long running processes and then this starts to become a problem. Next to that it’s of course good programming practise to clean up resources when they're not needed anymore. So even for the standard command line use case, this seems an improvement in resource management. Personally I see no downsides as the primary connection to the plugin is kept alive (the plugin is not killed) and only unused connections that will never be used again are closed to free up any related goroutines and memory.
81 lines
1.7 KiB
Go
81 lines
1.7 KiB
Go
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 {
|
|
var provider ResourceProvider
|
|
var resourceConfig *ResourceConfig
|
|
|
|
seq := make([]EvalNode, 0, 5)
|
|
seq = append(seq, &EvalInitProvider{Name: n})
|
|
|
|
// Input stuff
|
|
seq = append(seq, &EvalOpFilter{
|
|
Ops: []walkOperation{walkInput},
|
|
Node: &EvalSequence{
|
|
Nodes: []EvalNode{
|
|
&EvalGetProvider{
|
|
Name: n,
|
|
Output: &provider,
|
|
},
|
|
&EvalInterpolate{
|
|
Config: config,
|
|
Output: &resourceConfig,
|
|
},
|
|
&EvalBuildProviderConfig{
|
|
Provider: n,
|
|
Config: &resourceConfig,
|
|
Output: &resourceConfig,
|
|
},
|
|
&EvalInputProvider{
|
|
Name: n,
|
|
Provider: &provider,
|
|
Config: &resourceConfig,
|
|
},
|
|
},
|
|
},
|
|
})
|
|
|
|
// Apply stuff
|
|
seq = append(seq, &EvalOpFilter{
|
|
Ops: []walkOperation{walkValidate, walkRefresh, walkPlan, walkApply},
|
|
Node: &EvalSequence{
|
|
Nodes: []EvalNode{
|
|
&EvalGetProvider{
|
|
Name: n,
|
|
Output: &provider,
|
|
},
|
|
&EvalInterpolate{
|
|
Config: config,
|
|
Output: &resourceConfig,
|
|
},
|
|
&EvalBuildProviderConfig{
|
|
Provider: n,
|
|
Config: &resourceConfig,
|
|
Output: &resourceConfig,
|
|
},
|
|
&EvalValidateProvider{
|
|
Provider: &provider,
|
|
Config: &resourceConfig,
|
|
},
|
|
&EvalConfigProvider{
|
|
Provider: n,
|
|
Config: &resourceConfig,
|
|
},
|
|
},
|
|
},
|
|
})
|
|
|
|
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}
|
|
}
|