2019-10-14 10:43:59 -04:00
|
|
|
//go:generate mapstructure-to-hcl2 -type Provisioner
|
|
|
|
|
2019-04-08 07:38:55 -04:00
|
|
|
package sleep
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
|
|
|
|
2019-12-17 05:25:56 -05:00
|
|
|
"github.com/hashicorp/hcl/v2/hcldec"
|
2020-12-17 16:29:25 -05:00
|
|
|
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
|
|
|
|
"github.com/hashicorp/packer-plugin-sdk/template/config"
|
2019-04-08 07:38:55 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
type Provisioner struct {
|
|
|
|
Duration time.Duration
|
|
|
|
}
|
|
|
|
|
2020-12-01 17:25:14 -05:00
|
|
|
var _ packersdk.Provisioner = new(Provisioner)
|
2019-04-08 07:38:55 -04:00
|
|
|
|
2019-12-17 05:25:56 -05:00
|
|
|
func (p *Provisioner) ConfigSpec() hcldec.ObjectSpec { return p.FlatMapstructure().HCL2Spec() }
|
|
|
|
|
|
|
|
func (p *Provisioner) FlatConfig() interface{} { return p.FlatMapstructure() }
|
|
|
|
|
2019-04-08 07:38:55 -04:00
|
|
|
func (p *Provisioner) Prepare(raws ...interface{}) error {
|
|
|
|
return config.Decode(&p, &config.DecodeOpts{}, raws...)
|
|
|
|
}
|
|
|
|
|
2020-11-19 18:10:00 -05:00
|
|
|
func (p *Provisioner) Provision(ctx context.Context, _ packersdk.Ui, _ packersdk.Communicator, _ map[string]interface{}) error {
|
2019-04-08 07:38:55 -04:00
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
|
|
|
return ctx.Err()
|
|
|
|
case <-time.After(p.Duration):
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|