diff --git a/packer/template.go b/packer/template.go index 6c601d05b..f2f78f84b 100644 --- a/packer/template.go +++ b/packer/template.go @@ -9,6 +9,7 @@ import ( "io/ioutil" "os" "sort" + "time" ) // The rawTemplate struct represents the structure of a template read @@ -63,10 +64,13 @@ type RawPostProcessorConfig struct { type RawProvisionerConfig struct { TemplateOnlyExcept `mapstructure:",squash"` - Type string - Override map[string]interface{} + Type string + Override map[string]interface{} + RawPauseBefore string `mapstructure:"pause_before"` RawConfig interface{} + + pauseBefore time.Duration } // RawVariable represents a variable configuration within a template. @@ -289,6 +293,19 @@ func ParseTemplate(data []byte) (t *Template, err error) { } } + // Setup the pause settings + if raw.RawPauseBefore != "" { + duration, err := time.ParseDuration(raw.RawPauseBefore) + if err != nil { + errors = append( + errors, fmt.Errorf( + "provisioner %d: pause_before invalid: %s", + i+1, err)) + } + + raw.pauseBefore = duration + } + raw.RawConfig = v } diff --git a/packer/template_test.go b/packer/template_test.go index 053a4705d..5ab991d16 100644 --- a/packer/template_test.go +++ b/packer/template_test.go @@ -6,6 +6,7 @@ import ( "reflect" "sort" "testing" + "time" ) func testTemplateComponentFinder() *ComponentFinder { @@ -445,6 +446,38 @@ func TestParseTemplate_Provisioners(t *testing.T) { } } +func TestParseTemplate_ProvisionerPauseBefore(t *testing.T) { + data := ` + { + "builders": [{"type": "foo"}], + + "provisioners": [ + { + "type": "shell", + "pause_before": "10s" + } + ] + } + ` + + result, err := ParseTemplate([]byte(data)) + if err != nil { + t.Fatal("err: %s", err) + } + if result == nil { + t.Fatal("should have result") + } + if len(result.Provisioners) != 1 { + t.Fatalf("bad: %#v", result.Provisioners) + } + if result.Provisioners[0].Type != "shell" { + t.Fatalf("bad: %#v", result.Provisioners[0].Type) + } + if result.Provisioners[0].pauseBefore != 10 * time.Second { + t.Fatalf("bad: %s", result.Provisioners[0].pauseBefore) + } +} + func TestParseTemplate_Variables(t *testing.T) { data := ` {