github.com/subuk/terraform@v0.6.14-0.20160317140351-de1567c2e732/rpc/ui_input.go (about) 1 package rpc 2 3 import ( 4 "net/rpc" 5 6 "github.com/hashicorp/terraform/terraform" 7 ) 8 9 // UIInput is an implementatin of terraform.UIInput that communicates 10 // over RPC. 11 type UIInput struct { 12 Client *rpc.Client 13 Name string 14 } 15 16 func (i *UIInput) Input(opts *terraform.InputOpts) (string, error) { 17 var resp UIInputInputResponse 18 err := i.Client.Call(i.Name+".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 *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: NewBasicError(err), 48 } 49 50 return nil 51 }