From a35ac0127e090f721522d99bc25bb0c381d8106d Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Thu, 14 Nov 2019 16:12:39 -0800 Subject: [PATCH] fix bug in step_region_copy --- builder/amazon/ebs/step_create_ami.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/builder/amazon/ebs/step_create_ami.go b/builder/amazon/ebs/step_create_ami.go index ce69dae1f..137ffd4ed 100644 --- a/builder/amazon/ebs/step_create_ami.go +++ b/builder/amazon/ebs/step_create_ami.go @@ -66,15 +66,19 @@ func (s *stepCreateAMI) Run(ctx context.Context, state multistep.StateBag) multi ui.Say("Waiting for AMI to become ready...") if err := awscommon.WaitUntilAMIAvailable(ctx, ec2conn, *createResp.ImageId); err != nil { log.Printf("Error waiting for AMI: %s", err) - imagesResp, err := ec2conn.DescribeImages(&ec2.DescribeImagesInput{ImageIds: []*string{createResp.ImageId}}) - if err != nil { + imagesResp, imerr := ec2conn.DescribeImages(&ec2.DescribeImagesInput{ImageIds: []*string{createResp.ImageId}}) + if imerr != nil { log.Printf("Unable to determine reason waiting for AMI failed: %s", err) - err = fmt.Errorf("Unknown error waiting for AMI.") + err = fmt.Errorf("Unknown error waiting for AMI; %s", err) } else { - stateReason := imagesResp.Images[0].StateReason - err = fmt.Errorf("Error waiting for AMI. Reason: %s", stateReason) + if imagesResp != nil && len(imagesResp.Images) > 0 { + image := imagesResp.Images[0] + if image != nil { + stateReason := image.StateReason + err = fmt.Errorf("Error waiting for AMI. Reason: %s", stateReason) + } + } } - state.Put("error", err) ui.Error(err.Error()) return multistep.ActionHalt