Set default BMCS builder image name
Set the default image name to "packer-{{timestamp}}".
This commit is contained in:
parent
630ee5d650
commit
fc17f69bad
|
@ -188,8 +188,13 @@ func NewConfig(raws ...interface{}) (*Config, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.ImageName == "" {
|
if c.ImageName == "" {
|
||||||
errs = packer.MultiErrorAppend(
|
name, err := interpolate.Render("packer-{{timestamp}}", nil)
|
||||||
errs, errors.New("'image_name' must be specified"))
|
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 {
|
if errs != nil && len(errs.Errors) > 0 {
|
||||||
|
|
|
@ -130,10 +130,7 @@ func TestConfig(t *testing.T) {
|
||||||
|
|
||||||
// Test the correct errors are produced when required template keys are
|
// Test the correct errors are produced when required template keys are
|
||||||
// omitted.
|
// omitted.
|
||||||
requiredKeys := []string{
|
requiredKeys := []string{"availability_domain", "base_image_ocid", "shape", "subnet_ocid"}
|
||||||
"availability_domain", "base_image_ocid", "shape",
|
|
||||||
"image_name", "subnet_ocid",
|
|
||||||
}
|
|
||||||
for _, k := range requiredKeys {
|
for _, k := range requiredKeys {
|
||||||
t.Run(k+"_required", func(t *testing.T) {
|
t.Run(k+"_required", func(t *testing.T) {
|
||||||
raw := testConfig(cfgFile)
|
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
|
// Test that AccessCfgFile properties are overridden by their
|
||||||
// corosponding template keys.
|
// corosponding template keys.
|
||||||
accessOverrides := map[string]string{
|
accessOverrides := map[string]string{
|
||||||
|
|
Loading…
Reference in New Issue