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.
48 lines
1.1 KiB
Go
48 lines
1.1 KiB
Go
package terraform
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
// EvalInitProvisioner is an EvalNode implementation that initializes a provisioner
|
|
// and returns nothing. The provisioner can be retrieved again with the
|
|
// EvalGetProvisioner node.
|
|
type EvalInitProvisioner struct {
|
|
Name string
|
|
}
|
|
|
|
func (n *EvalInitProvisioner) Eval(ctx EvalContext) (interface{}, error) {
|
|
return ctx.InitProvisioner(n.Name)
|
|
}
|
|
|
|
// EvalCloseProvisioner is an EvalNode implementation that closes provisioner
|
|
// connections that aren't needed anymore.
|
|
type EvalCloseProvisioner struct {
|
|
Name string
|
|
}
|
|
|
|
func (n *EvalCloseProvisioner) Eval(ctx EvalContext) (interface{}, error) {
|
|
ctx.CloseProvisioner(n.Name)
|
|
return nil, nil
|
|
}
|
|
|
|
// EvalGetProvisioner is an EvalNode implementation that retrieves an already
|
|
// initialized provisioner instance for the given name.
|
|
type EvalGetProvisioner struct {
|
|
Name string
|
|
Output *ResourceProvisioner
|
|
}
|
|
|
|
func (n *EvalGetProvisioner) Eval(ctx EvalContext) (interface{}, error) {
|
|
result := ctx.Provisioner(n.Name)
|
|
if result == nil {
|
|
return nil, fmt.Errorf("provisioner %s not initialized", n.Name)
|
|
}
|
|
|
|
if n.Output != nil {
|
|
*n.Output = result
|
|
}
|
|
|
|
return result, nil
|
|
}
|