mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-24 16:10:46 -06:00
plugin: Adding support for provisioners
This commit is contained in:
parent
cfc7b69bb1
commit
3849ca80ef
@ -60,6 +60,12 @@ func TestHelperProcess(*testing.T) {
|
||||
log.Printf("[ERR] %s", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
case "resource-provisioner":
|
||||
err := Serve(new(terraform.MockResourceProvisioner))
|
||||
if err != nil {
|
||||
log.Printf("[ERR] %s", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
case "invalid-rpc-address":
|
||||
fmt.Println("lolinvalid")
|
||||
case "mock":
|
||||
|
35
plugin/resource_provisioner.go
Normal file
35
plugin/resource_provisioner.go
Normal file
@ -0,0 +1,35 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
|
||||
tfrpc "github.com/hashicorp/terraform/rpc"
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
)
|
||||
|
||||
// ResourceProvisionerFactory returns a Terraform ResourceProvisionerFactory
|
||||
// that executes a plugin and connects to it.
|
||||
func ResourceProvisionerFactory(cmd *exec.Cmd) terraform.ResourceProvisionerFactory {
|
||||
return func() (terraform.ResourceProvisioner, error) {
|
||||
config := &ClientConfig{
|
||||
Cmd: cmd,
|
||||
Managed: true,
|
||||
}
|
||||
|
||||
client := NewClient(config)
|
||||
rpcClient, err := client.Client()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
rpcName, err := client.Service()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &tfrpc.ResourceProvisioner{
|
||||
Client: rpcClient,
|
||||
Name: rpcName,
|
||||
}, nil
|
||||
}
|
||||
}
|
23
plugin/resource_provisioner_test.go
Normal file
23
plugin/resource_provisioner_test.go
Normal file
@ -0,0 +1,23 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestResourceProvisioner(t *testing.T) {
|
||||
c := NewClient(&ClientConfig{Cmd: helperProcess("resource-provisioner")})
|
||||
defer c.Kill()
|
||||
|
||||
_, err := c.Client()
|
||||
if err != nil {
|
||||
t.Fatalf("should not have error: %s", err)
|
||||
}
|
||||
|
||||
service, err := c.Service()
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
if service == "" {
|
||||
t.Fatal("service should not be blank")
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user