mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-28 18:01:01 -06:00
84214437b3
This replaces this plugin system with the extracted hashicorp/go-plugin library. This doesn't introduce any new features such as binary flattening but opens us up to that a lot more easily and removes a lot of code from TF in favor of the upstream lib. This will introduce a protocol change that will cause all existing plugins to have to be recompiled to work properly. There is no actual API changes so they just have to recompile, but it is technically backwards incompatible.
48 lines
1.4 KiB
Go
48 lines
1.4 KiB
Go
package plugin
|
|
|
|
import (
|
|
"github.com/hashicorp/go-plugin"
|
|
"github.com/hashicorp/terraform/terraform"
|
|
)
|
|
|
|
// The constants below are the names of the plugins that can be dispensed
|
|
// from the plugin server.
|
|
const (
|
|
ProviderPluginName = "provider"
|
|
ProvisionerPluginName = "provisioner"
|
|
)
|
|
|
|
// Handshake is the HandshakeConfig used to configure clients and servers.
|
|
var Handshake = plugin.HandshakeConfig{
|
|
ProtocolVersion: 1,
|
|
MagicCookieKey: "TF_PLUGIN_MAGIC_COOKIE",
|
|
MagicCookieValue: "d602bf8f470bc67ca7faa0386276bbdd4330efaf76d1a219cb4d6991ca9872b2",
|
|
}
|
|
|
|
type ProviderFunc func() terraform.ResourceProvider
|
|
type ProvisionerFunc func() terraform.ResourceProvisioner
|
|
|
|
// ServeOpts are the configurations to serve a plugin.
|
|
type ServeOpts struct {
|
|
ProviderFunc ProviderFunc
|
|
ProvisionerFunc ProvisionerFunc
|
|
}
|
|
|
|
// Serve serves a plugin. This function never returns and should be the final
|
|
// function called in the main function of the plugin.
|
|
func Serve(opts *ServeOpts) {
|
|
plugin.Serve(&plugin.ServeConfig{
|
|
HandshakeConfig: Handshake,
|
|
Plugins: pluginMap(opts),
|
|
})
|
|
}
|
|
|
|
// pluginMap returns the map[string]plugin.Plugin to use for configuring a plugin
|
|
// server or client.
|
|
func pluginMap(opts *ServeOpts) map[string]plugin.Plugin {
|
|
return map[string]plugin.Plugin{
|
|
"provider": &ResourceProviderPlugin{F: opts.ProviderFunc},
|
|
"provisioner": &ResourceProvisionerPlugin{F: opts.ProvisionerFunc},
|
|
}
|
|
}
|