Commit ca70cd8f authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

packer: Tempaltes understand "pause_before" in provisioners

parent 5eb16895
......@@ -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
}
......
......@@ -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 := `
{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment