From fdd3b594b9f09cf593c78d2b75a2c423b8237a57 Mon Sep 17 00:00:00 2001 From: Marin Salinas Date: Thu, 31 Jan 2019 10:17:39 -0600 Subject: [PATCH] fix: add function to validate if image name exists --- builder/osc/bsusurrogate/builder_acc_test.go | 2 +- builder/osc/common/step_pre_validate.go | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/builder/osc/bsusurrogate/builder_acc_test.go b/builder/osc/bsusurrogate/builder_acc_test.go index 5fccd79ef..00afeb182 100644 --- a/builder/osc/bsusurrogate/builder_acc_test.go +++ b/builder/osc/bsusurrogate/builder_acc_test.go @@ -27,7 +27,7 @@ const testBuilderAccBasic = ` "type": "test", "region": "eu-west-2", "vm_type": "m3.medium", - "source_omi": "ami-76b2a71e", + "source_omi": "ami-46260446", "ssh_username": "ubuntu", "omi_name": "packer-test {{timestamp}}", "omi_virtualization_type": "hvm", diff --git a/builder/osc/common/step_pre_validate.go b/builder/osc/common/step_pre_validate.go index 2d74d9e7c..1b31232aa 100644 --- a/builder/osc/common/step_pre_validate.go +++ b/builder/osc/common/step_pre_validate.go @@ -38,7 +38,17 @@ func (s *StepPreValidate) Run(_ context.Context, state multistep.StateBag) multi return multistep.ActionHalt } - if len(resp.OK.Images) > 0 { + //FIXME: Remove when the oAPI filters works + images := make([]oapi.Image, 0) + + for _, omi := range resp.OK.Images { + if omi.ImageName == s.DestOmiName { + images = append(images, omi) + } + } + + //if len(resp.OK.Images) > 0 { + if len(images) > 0 { err := fmt.Errorf("Error: name conflicts with an existing OMI: %s", resp.OK.Images[0].ImageId) state.Put("error", err) ui.Error(err.Error())