2015-06-19 18:06:06 -04:00
|
|
|
package shell
|
|
|
|
|
|
|
|
import (
|
2019-03-19 13:11:19 -04:00
|
|
|
"context"
|
|
|
|
|
2019-12-17 05:25:56 -05:00
|
|
|
"github.com/hashicorp/hcl/v2/hcldec"
|
2020-11-19 14:54:31 -05:00
|
|
|
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
2020-11-12 17:44:02 -05:00
|
|
|
sl "github.com/hashicorp/packer/packer-plugin-sdk/shell-local"
|
2015-06-19 18:06:06 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
type Provisioner struct {
|
2018-02-27 15:50:42 -05:00
|
|
|
config sl.Config
|
2015-06-19 18:06:06 -04:00
|
|
|
}
|
|
|
|
|
2019-12-17 05:25:56 -05:00
|
|
|
func (p *Provisioner) ConfigSpec() hcldec.ObjectSpec { return p.config.FlatMapstructure().HCL2Spec() }
|
|
|
|
|
2015-06-19 18:06:06 -04:00
|
|
|
func (p *Provisioner) Prepare(raws ...interface{}) error {
|
2018-03-02 15:32:34 -05:00
|
|
|
err := sl.Decode(&p.config, raws...)
|
2015-06-19 18:06:06 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-03-02 15:32:34 -05:00
|
|
|
err = sl.Validate(&p.config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-11-19 18:10:00 -05:00
|
|
|
func (p *Provisioner) Provision(ctx context.Context, ui packersdk.Ui, _ packersdk.Communicator, generatedData map[string]interface{}) error {
|
2019-12-12 13:59:44 -05:00
|
|
|
_, retErr := sl.Run(ctx, ui, &p.config, generatedData)
|
2015-06-19 18:06:06 -04:00
|
|
|
|
2019-06-12 16:18:57 -04:00
|
|
|
return retErr
|
2015-06-19 18:06:06 -04:00
|
|
|
}
|