driftctl/pkg/terraform/plugin_client.go

30 lines
814 B
Go
Raw Normal View History

package terraform
import (
"os/exec"
2021-02-10 13:25:07 +00:00
"github.com/cloudskiff/driftctl/logger"
tfplugin "github.com/hashicorp/terraform/plugin"
"github.com/hashicorp/go-plugin"
"github.com/hashicorp/terraform/plugin/discovery"
)
func ClientConfig(m discovery.PluginMeta) *plugin.ClientConfig {
2021-02-10 13:25:07 +00:00
logger := logger.NewTerraformPluginLogger()
return &plugin.ClientConfig{
Cmd: exec.Command(m.Path),
HandshakeConfig: tfplugin.Handshake,
VersionedPlugins: tfplugin.VersionedPlugins,
Managed: true,
2021-02-10 13:25:07 +00:00
Logger: logger,
AllowedProtocols: []plugin.Protocol{plugin.ProtocolGRPC},
AutoMTLS: true,
}
}
// Client returns a plugin client for the plugin described by the given metadata.
func Client(m discovery.PluginMeta) *plugin.Client {
return plugin.NewClient(ClientConfig(m))
}