diff --git a/builder/oracle/bmcs/config.go b/builder/oracle/bmcs/config.go index 689054db3..c46dec5cc 100644 --- a/builder/oracle/bmcs/config.go +++ b/builder/oracle/bmcs/config.go @@ -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 { diff --git a/builder/oracle/bmcs/config_test.go b/builder/oracle/bmcs/config_test.go index 2fb4123c7..7d81fa097 100644 --- a/builder/oracle/bmcs/config_test.go +++ b/builder/oracle/bmcs/config_test.go @@ -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{