From c27f3e944504704139694e5713087aa187eb58e6 Mon Sep 17 00:00:00 2001 From: AlessioT Date: Sat, 28 Apr 2018 11:00:33 +0100 Subject: [PATCH 1/4] alessio.tomasino@yahoo.co.uk --- builder/amazon/ebs/step_create_ami.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/builder/amazon/ebs/step_create_ami.go b/builder/amazon/ebs/step_create_ami.go index 0dde4fc30..bee540da9 100644 --- a/builder/amazon/ebs/step_create_ami.go +++ b/builder/amazon/ebs/step_create_ami.go @@ -52,13 +52,16 @@ func (s *stepCreateAMI) Run(_ context.Context, state multistep.StateBag) multist ui.Say("Waiting for AMI to become ready...") if _, err := awscommon.WaitForState(&stateChange); err != nil { - err := fmt.Errorf("Error waiting for AMI: %s", err) + imagesResp, _ := ec2conn.DescribeImages(&ec2.DescribeImagesInput{ImageIds: []*string{createResp.ImageId}}) + stateReason := imagesResp.Images[0].StateReason.Message + err := fmt.Errorf("Error waiting for AMI: %s. Cause: %s", err, *stateReason) state.Put("error", err) ui.Error(err.Error()) return multistep.ActionHalt } imagesResp, err := ec2conn.DescribeImages(&ec2.DescribeImagesInput{ImageIds: []*string{createResp.ImageId}}) + if err != nil { err := fmt.Errorf("Error searching for AMI: %s", err) state.Put("error", err) From 09bb21774d30f3768806cc94e688448e0950621b Mon Sep 17 00:00:00 2001 From: AlessioT Date: Sat, 28 Apr 2018 11:02:53 +0100 Subject: [PATCH 2/4] alessio.tomasino@yahoo.co.uk --- builder/amazon/ebs/step_create_ami.go | 1 - 1 file changed, 1 deletion(-) diff --git a/builder/amazon/ebs/step_create_ami.go b/builder/amazon/ebs/step_create_ami.go index bee540da9..1c3bd18e2 100644 --- a/builder/amazon/ebs/step_create_ami.go +++ b/builder/amazon/ebs/step_create_ami.go @@ -61,7 +61,6 @@ func (s *stepCreateAMI) Run(_ context.Context, state multistep.StateBag) multist } imagesResp, err := ec2conn.DescribeImages(&ec2.DescribeImagesInput{ImageIds: []*string{createResp.ImageId}}) - if err != nil { err := fmt.Errorf("Error searching for AMI: %s", err) state.Put("error", err) From 373226e9c516be93d9d016fd6d082536bd6d4fe5 Mon Sep 17 00:00:00 2001 From: AlessioT Date: Sat, 28 Apr 2018 12:40:48 +0100 Subject: [PATCH 3/4] Extract state reason for failure --- builder/amazon/ebs/step_create_ami.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builder/amazon/ebs/step_create_ami.go b/builder/amazon/ebs/step_create_ami.go index 1c3bd18e2..254311fcd 100644 --- a/builder/amazon/ebs/step_create_ami.go +++ b/builder/amazon/ebs/step_create_ami.go @@ -54,7 +54,7 @@ func (s *stepCreateAMI) Run(_ context.Context, state multistep.StateBag) multist if _, err := awscommon.WaitForState(&stateChange); err != nil { imagesResp, _ := ec2conn.DescribeImages(&ec2.DescribeImagesInput{ImageIds: []*string{createResp.ImageId}}) stateReason := imagesResp.Images[0].StateReason.Message - err := fmt.Errorf("Error waiting for AMI: %s. Cause: %s", err, *stateReason) + err := fmt.Errorf("Error waiting for AMI: %s. Root cause: %s", err, *stateReason) state.Put("error", err) ui.Error(err.Error()) return multistep.ActionHalt From 3d4c7d0df173c063c07aa8c4b5a298a9c2eddadd Mon Sep 17 00:00:00 2001 From: AlessioT Date: Mon, 30 Apr 2018 20:59:13 +0100 Subject: [PATCH 4/4] Feature Request: Log reason why AMI creation failed --- builder/amazon/ebs/step_create_ami.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/builder/amazon/ebs/step_create_ami.go b/builder/amazon/ebs/step_create_ami.go index 254311fcd..1f0ad717c 100644 --- a/builder/amazon/ebs/step_create_ami.go +++ b/builder/amazon/ebs/step_create_ami.go @@ -52,9 +52,15 @@ func (s *stepCreateAMI) Run(_ context.Context, state multistep.StateBag) multist ui.Say("Waiting for AMI to become ready...") if _, err := awscommon.WaitForState(&stateChange); err != nil { - imagesResp, _ := ec2conn.DescribeImages(&ec2.DescribeImagesInput{ImageIds: []*string{createResp.ImageId}}) - stateReason := imagesResp.Images[0].StateReason.Message - err := fmt.Errorf("Error waiting for AMI: %s. Root cause: %s", err, *stateReason) + err := fmt.Errorf("Error waiting for AMI: %s", err) + imagesResp, err := ec2conn.DescribeImages(&ec2.DescribeImagesInput{ImageIds: []*string{createResp.ImageId}}) + if err != nil { + stateReason := imagesResp.Images[0].StateReason.Message + if stateReason != nil { + err = fmt.Errorf("%s. Root cause: %s", err.Error(), *stateReason) + } + } + state.Put("error", err) ui.Error(err.Error()) return multistep.ActionHalt