fix: add function to validate if image name exists

This commit is contained in:
Marin Salinas 2019-01-31 10:17:39 -06:00 committed by Megan Marsh
parent 33d1671e4c
commit fdd3b594b9
2 changed files with 12 additions and 2 deletions

View File

@ -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",

View File

@ -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())