diff --git a/packer/plugin/provisioner.go b/packer/plugin/provisioner.go index 3655bb798..33078072f 100644 --- a/packer/plugin/provisioner.go +++ b/packer/plugin/provisioner.go @@ -13,13 +13,13 @@ type cmdProvisioner struct { client *client } -func (c *cmdProvisioner) Prepare(configs ...interface{}) { +func (c *cmdProvisioner) Prepare(configs ...interface{}) error { defer func() { r := recover() c.checkExit(r, nil) }() - c.p.Prepare(configs...) + return c.p.Prepare(configs...) } func (c *cmdProvisioner) Provision(ui packer.Ui, comm packer.Communicator) { diff --git a/packer/plugin/provisioner_test.go b/packer/plugin/provisioner_test.go index dc0bb4d88..eaf08822a 100644 --- a/packer/plugin/provisioner_test.go +++ b/packer/plugin/provisioner_test.go @@ -9,7 +9,9 @@ import ( type helperProvisioner byte -func (helperProvisioner) Prepare(...interface{}) {} +func (helperProvisioner) Prepare(...interface{}) error { + return nil +} func (helperProvisioner) Provision(packer.Ui, packer.Communicator) {} diff --git a/packer/provisioner.go b/packer/provisioner.go index 06ce49630..cfd2ffbd1 100644 --- a/packer/provisioner.go +++ b/packer/provisioner.go @@ -6,7 +6,7 @@ type Provisioner interface { // Prepare is called with a set of configurations to setup the // internal state of the provisioner. The multiple configurations // should be merged in some sane way. - Prepare(...interface{}) + Prepare(...interface{}) error // Provision is called to actually provision the machine. A UI is // given to communicate with the user, and a communicator is given that diff --git a/packer/provisioner_test.go b/packer/provisioner_test.go index cf800e4d6..49ab76dea 100644 --- a/packer/provisioner_test.go +++ b/packer/provisioner_test.go @@ -8,9 +8,10 @@ type TestProvisioner struct { provCalled bool } -func (t *TestProvisioner) Prepare(configs ...interface{}) { +func (t *TestProvisioner) Prepare(configs ...interface{}) error { t.prepCalled = true t.prepConfigs = configs + return nil } func (t *TestProvisioner) Provision(Ui, Communicator) { diff --git a/packer/rpc/provisioner.go b/packer/rpc/provisioner.go index e66a974c5..f2da4772d 100644 --- a/packer/rpc/provisioner.go +++ b/packer/rpc/provisioner.go @@ -28,9 +28,13 @@ type ProvisionerProvisionArgs struct { func Provisioner(client *rpc.Client) *provisioner { return &provisioner{client} } -func (p *provisioner) Prepare(configs ...interface{}) { +func (p *provisioner) Prepare(configs ...interface{}) (err error) { args := &ProvisionerPrepareArgs{configs} - p.client.Call("Provisioner.Prepare", args, new(interface{})) + if cerr := p.client.Call("Provisioner.Prepare", args, &err); cerr != nil { + err = cerr + } + + return } func (p *provisioner) Provision(ui packer.Ui, comm packer.Communicator) { @@ -43,8 +47,8 @@ func (p *provisioner) Provision(ui packer.Ui, comm packer.Communicator) { p.client.Call("Provisioner.Provision", args, new(interface{})) } -func (p *ProvisionerServer) Prepare(args *ProvisionerPrepareArgs, reply *interface{}) error { - p.p.Prepare(args.Configs...) +func (p *ProvisionerServer) Prepare(args *ProvisionerPrepareArgs, reply *error) error { + *reply = p.p.Prepare(args.Configs...) return nil } diff --git a/packer/rpc/provisioner_test.go b/packer/rpc/provisioner_test.go index c8dc1a696..293027388 100644 --- a/packer/rpc/provisioner_test.go +++ b/packer/rpc/provisioner_test.go @@ -15,9 +15,10 @@ type testProvisioner struct { provUi packer.Ui } -func (p *testProvisioner) Prepare(configs ...interface{}) { +func (p *testProvisioner) Prepare(configs ...interface{}) error { p.prepareCalled = true p.prepareConfigs = configs + return nil } func (p *testProvisioner) Provision(ui packer.Ui, comm packer.Communicator) { diff --git a/provisioner/shell/provisioner.go b/provisioner/shell/provisioner.go index 74d31dd34..365233b28 100644 --- a/provisioner/shell/provisioner.go +++ b/provisioner/shell/provisioner.go @@ -29,15 +29,19 @@ type Provisioner struct { config config } -func (p *Provisioner) Prepare(raws ...interface{}) { +func (p *Provisioner) Prepare(raws ...interface{}) error { // TODO: errors for _, raw := range raws { - _ = mapstructure.Decode(raw, &p.config) + if err := mapstructure.Decode(raw, &p.config); err != nil { + return err + } } if p.config.RemotePath == "" { p.config.RemotePath = DefaultRemotePath } + + return nil } func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) { diff --git a/provisioner/shell/provisioner_test.go b/provisioner/shell/provisioner_test.go index d3d721c52..5da089187 100644 --- a/provisioner/shell/provisioner_test.go +++ b/provisioner/shell/provisioner_test.go @@ -17,7 +17,10 @@ func TestProvisionerPrepare_Defaults(t *testing.T) { raw := map[string]interface{}{} p := &Provisioner{} - p.Prepare(raw, nil) + err := p.Prepare(raw) + if err != nil { + t.Fatalf("err: %s", err) + } if p.config.RemotePath != DefaultRemotePath { t.Errorf("unexpected remote path: %s", p.config.RemotePath)