From 39c25b2c661a2565f2506476ea292ac81507dd36 Mon Sep 17 00:00:00 2001 From: Sylvia Moss Date: Thu, 16 Jan 2020 14:38:46 +0100 Subject: [PATCH] Add retry mechanism to amazon DeleteSnapshot (#8614) --- builder/amazon/common/helper_funcs.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/builder/amazon/common/helper_funcs.go b/builder/amazon/common/helper_funcs.go index 4d5d07125..f614b15ef 100644 --- a/builder/amazon/common/helper_funcs.go +++ b/builder/amazon/common/helper_funcs.go @@ -50,8 +50,18 @@ func DestroyAMIs(imageids []*string, ec2conn *ec2.EC2) error { // Delete snapshot(s) by image for _, b := range i.BlockDeviceMappings { if b.Ebs != nil && aws.StringValue(b.Ebs.SnapshotId) != "" { - _, err := ec2conn.DeleteSnapshot(&ec2.DeleteSnapshotInput{ - SnapshotId: b.Ebs.SnapshotId, + + err = retry.Config{ + Tries: 11, + ShouldRetry: func(err error) bool { + return isAWSErr(err, "UnauthorizedOperation", "") + }, + RetryDelay: (&retry.Backoff{InitialBackoff: 200 * time.Millisecond, MaxBackoff: 30 * time.Second, Multiplier: 2}).Linear, + }.Run(ctx, func(ctx context.Context) error { + _, err := ec2conn.DeleteSnapshot(&ec2.DeleteSnapshotInput{ + SnapshotId: b.Ebs.SnapshotId, + }) + return err }) if err != nil {