]> git.immae.eu Git - github/fretlink/terraform-provider-statuscake.git/blame - vendor/github.com/hashicorp/terraform/plugin/ui_input.go
Merge pull request #32 from ndench/0.12-compatibility
[github/fretlink/terraform-provider-statuscake.git] / vendor / github.com / hashicorp / terraform / plugin / ui_input.go
CommitLineData
bae9f6d2
JC
1package plugin
2
3import (
107c1cdb 4 "context"
bae9f6d2
JC
5 "net/rpc"
6
7 "github.com/hashicorp/go-plugin"
8 "github.com/hashicorp/terraform/terraform"
9)
10
107c1cdb 11// UIInput is an implementation of terraform.UIInput that communicates
bae9f6d2
JC
12// over RPC.
13type UIInput struct {
14 Client *rpc.Client
15}
16
107c1cdb 17func (i *UIInput) Input(ctx context.Context, opts *terraform.InputOpts) (string, error) {
bae9f6d2
JC
18 var resp UIInputInputResponse
19 err := i.Client.Call("Plugin.Input", opts, &resp)
20 if err != nil {
21 return "", err
22 }
23 if resp.Error != nil {
24 err = resp.Error
25 return "", err
26 }
27
28 return resp.Value, nil
29}
30
31type UIInputInputResponse struct {
32 Value string
33 Error *plugin.BasicError
34}
35
36// UIInputServer is a net/rpc compatible structure for serving
37// a UIInputServer. This should not be used directly.
38type UIInputServer struct {
39 UIInput terraform.UIInput
40}
41
42func (s *UIInputServer) Input(
43 opts *terraform.InputOpts,
44 reply *UIInputInputResponse) error {
107c1cdb 45 value, err := s.UIInput.Input(context.Background(), opts)
bae9f6d2
JC
46 *reply = UIInputInputResponse{
47 Value: value,
48 Error: plugin.NewBasicError(err),
49 }
50
51 return nil
52}