Set default BMCS builder image name

Set the default image name to "packer-{{timestamp}}".
This commit is contained in:
Andrew Pryde 2017-08-02 10:51:08 +01:00
parent 630ee5d650
commit fc17f69bad
2 changed files with 22 additions and 6 deletions

View File

@ -188,8 +188,13 @@ func NewConfig(raws ...interface{}) (*Config, error) {
}
if c.ImageName == "" {
errs = packer.MultiErrorAppend(
errs, errors.New("'image_name' must be specified"))
name, err := interpolate.Render("packer-{{timestamp}}", nil)
if err != nil {
errs = packer.MultiErrorAppend(errs,
fmt.Errorf("unable to parse image name: %s", err))
} else {
c.ImageName = name
}
}
if errs != nil && len(errs.Errors) > 0 {

View File

@ -130,10 +130,7 @@ func TestConfig(t *testing.T) {
// Test the correct errors are produced when required template keys are
// omitted.
requiredKeys := []string{
"availability_domain", "base_image_ocid", "shape",
"image_name", "subnet_ocid",
}
requiredKeys := []string{"availability_domain", "base_image_ocid", "shape", "subnet_ocid"}
for _, k := range requiredKeys {
t.Run(k+"_required", func(t *testing.T) {
raw := testConfig(cfgFile)
@ -147,6 +144,20 @@ func TestConfig(t *testing.T) {
})
}
t.Run("ImageNameDefaultedIfEmpty", func(t *testing.T) {
raw := testConfig(cfgFile)
delete(raw, "image_name")
c, errs := NewConfig(raw)
if errs != nil {
t.Errorf("Unexpected error(s): %s", errs)
}
if !strings.Contains(c.ImageName, "packer-") {
t.Errorf("got default ImageName %q, want image name 'packer-{{timestamp}}'", c.ImageName)
}
})
// Test that AccessCfgFile properties are overridden by their
// corosponding template keys.
accessOverrides := map[string]string{