]>
Commit | Line | Data |
---|---|---|
bae9f6d2 JC |
1 | package plugin |
2 | ||
3 | import ( | |
4 | "net/rpc" | |
5 | ||
6 | "github.com/hashicorp/go-plugin" | |
7 | "github.com/hashicorp/terraform/terraform" | |
8 | ) | |
9 | ||
10 | // UIInput is an implementatin of terraform.UIInput that communicates | |
11 | // over RPC. | |
12 | type UIInput struct { | |
13 | Client *rpc.Client | |
14 | } | |
15 | ||
16 | func (i *UIInput) Input(opts *terraform.InputOpts) (string, error) { | |
17 | var resp UIInputInputResponse | |
18 | err := i.Client.Call("Plugin.Input", opts, &resp) | |
19 | if err != nil { | |
20 | return "", err | |
21 | } | |
22 | if resp.Error != nil { | |
23 | err = resp.Error | |
24 | return "", err | |
25 | } | |
26 | ||
27 | return resp.Value, nil | |
28 | } | |
29 | ||
30 | type UIInputInputResponse struct { | |
31 | Value string | |
32 | Error *plugin.BasicError | |
33 | } | |
34 | ||
35 | // UIInputServer is a net/rpc compatible structure for serving | |
36 | // a UIInputServer. This should not be used directly. | |
37 | type UIInputServer struct { | |
38 | UIInput terraform.UIInput | |
39 | } | |
40 | ||
41 | func (s *UIInputServer) Input( | |
42 | opts *terraform.InputOpts, | |
43 | reply *UIInputInputResponse) error { | |
44 | value, err := s.UIInput.Input(opts) | |
45 | *reply = UIInputInputResponse{ | |
46 | Value: value, | |
47 | Error: plugin.NewBasicError(err), | |
48 | } | |
49 | ||
50 | return nil | |
51 | } |