plugin: Adding support for provisioners

This commit is contained in:
Armon Dadgar 2014-07-09 11:03:19 -07:00
parent cfc7b69bb1
commit 3849ca80ef
3 changed files with 64 additions and 0 deletions

View File

@ -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":

View 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
}
}

View 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")
}
}