diff --git a/builder/openstack/step_source_image_info.go b/builder/openstack/step_source_image_info.go index 035ef9d00..bdd0b25b5 100644 --- a/builder/openstack/step_source_image_info.go +++ b/builder/openstack/step_source_image_info.go @@ -38,15 +38,13 @@ func (s *StepSourceImageInfo) Run(_ context.Context, state multistep.StateBag) m } switch len(i) { - case 0: - return false, fmt.Errorf("No image was found matching filters: %v", s.SourceImageOpts) case 1: *image = i[0] - return true, nil + return false, nil default: if s.SourceMostRecent { *image = i[0] - return true, nil + return false, nil } return false, fmt.Errorf( "Your query returned more than one result. Please try a more specific search, or set most_recent to true. Search filters: %v", @@ -54,6 +52,13 @@ func (s *StepSourceImageInfo) Run(_ context.Context, state multistep.StateBag) m } }) + if image.ID == "" { + err := fmt.Errorf("No image was found matching filters: %v", s.SourceImageOpts) + state.Put("error", err) + ui.Error(err.Error()) + return multistep.ActionHalt + } + if err != nil { err := fmt.Errorf("Error querying image: %s", err) state.Put("error", err)