2020-12-09 15:31:34 +00:00
|
|
|
package terraform
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os/exec"
|
|
|
|
|
2021-02-10 13:25:07 +00:00
|
|
|
"github.com/cloudskiff/driftctl/logger"
|
2020-12-09 15:31:34 +00:00
|
|
|
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()
|
2020-12-09 15:31:34 +00:00
|
|
|
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,
|
2020-12-09 15:31:34 +00:00
|
|
|
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))
|
|
|
|
}
|