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"
|
2019-04-08 07:38:55 -04:00
|
|
|
"github.com/hashicorp/packer/packer"
|
2020-11-19 14:54:31 -05:00
|
|
|
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
2020-11-18 13:34:59 -05:00
|
|
|
"github.com/hashicorp/packer/packer-plugin-sdk/template/config"
|
2019-04-08 07:38:55 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
type Provisioner struct {
|
|
|
|
Duration time.Duration
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ packer.Provisioner = new(Provisioner)
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|