2014-05-29 00:07:47 +02:00
|
|
|
package rpc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/rpc"
|
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
)
|
|
|
|
|
2014-05-29 06:27:10 +02:00
|
|
|
// ResourceProvider is an implementation of terraform.ResourceProvider
|
|
|
|
// that communicates over RPC.
|
2014-05-29 00:07:47 +02:00
|
|
|
type ResourceProvider struct {
|
|
|
|
Client *rpc.Client
|
2014-05-29 00:18:14 +02:00
|
|
|
Name string
|
2014-05-29 00:07:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p *ResourceProvider) Configure(c map[string]interface{}) ([]string, error) {
|
|
|
|
var resp ResourceProviderConfigureResponse
|
2014-05-29 00:18:14 +02:00
|
|
|
err := p.Client.Call(p.Name+".Configure", c, &resp)
|
2014-05-29 00:07:47 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2014-05-29 00:31:09 +02:00
|
|
|
if resp.Error != nil {
|
|
|
|
err = resp.Error
|
|
|
|
}
|
2014-05-29 00:07:47 +02:00
|
|
|
|
2014-05-29 00:31:09 +02:00
|
|
|
return resp.Warnings, err
|
2014-05-29 00:07:47 +02:00
|
|
|
}
|
|
|
|
|
2014-06-03 23:26:31 +02:00
|
|
|
func (p *ResourceProvider) Resources() []terraform.ResourceType {
|
|
|
|
var result []terraform.ResourceType
|
|
|
|
|
|
|
|
err := p.Client.Call(p.Name+".Resources", new(interface{}), &result)
|
|
|
|
if err != nil {
|
|
|
|
// TODO: panic, log, what?
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
2014-05-29 06:27:10 +02:00
|
|
|
// ResourceProviderServer is a net/rpc compatible structure for serving
|
|
|
|
// a ResourceProvider. This should not be used directly.
|
2014-05-29 00:07:47 +02:00
|
|
|
type ResourceProviderServer struct {
|
|
|
|
Provider terraform.ResourceProvider
|
|
|
|
}
|
|
|
|
|
|
|
|
type ResourceProviderConfigureResponse struct {
|
|
|
|
Warnings []string
|
2014-05-29 00:31:09 +02:00
|
|
|
Error *BasicError
|
2014-05-29 00:07:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ResourceProviderServer) Configure(
|
|
|
|
config map[string]interface{},
|
|
|
|
reply *ResourceProviderConfigureResponse) error {
|
|
|
|
warnings, err := s.Provider.Configure(config)
|
|
|
|
*reply = ResourceProviderConfigureResponse{
|
|
|
|
Warnings: warnings,
|
2014-05-29 00:31:09 +02:00
|
|
|
Error: NewBasicError(err),
|
2014-05-29 00:07:47 +02:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2014-06-03 23:26:31 +02:00
|
|
|
|
|
|
|
func (s *ResourceProviderServer) Resources(
|
|
|
|
nothing interface{},
|
|
|
|
result *[]terraform.ResourceType) error {
|
|
|
|
*result = s.Provider.Resources()
|
|
|
|
return nil
|
|
|
|
}
|