Adding retry for ImportImage call in amazon-import post-processor.

This commit is contained in:
Geoff Schultz 2020-07-06 09:41:13 -05:00
parent 1454f4f6a1
commit 8010a23b34
1 changed files with 10 additions and 1 deletions

View File

@ -8,6 +8,7 @@ import (
"log" "log"
"os" "os"
"strings" "strings"
"time"
"github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2" "github.com/aws/aws-sdk-go/service/ec2"
@ -16,6 +17,7 @@ import (
"github.com/hashicorp/hcl/v2/hcldec" "github.com/hashicorp/hcl/v2/hcldec"
awscommon "github.com/hashicorp/packer/builder/amazon/common" awscommon "github.com/hashicorp/packer/builder/amazon/common"
"github.com/hashicorp/packer/common" "github.com/hashicorp/packer/common"
"github.com/hashicorp/packer/common/retry"
"github.com/hashicorp/packer/helper/config" "github.com/hashicorp/packer/helper/config"
"github.com/hashicorp/packer/packer" "github.com/hashicorp/packer/packer"
"github.com/hashicorp/packer/template/interpolate" "github.com/hashicorp/packer/template/interpolate"
@ -231,7 +233,14 @@ func (p *PostProcessor) PostProcess(ctx context.Context, ui packer.Ui, artifact
params.LicenseType = &p.config.LicenseType params.LicenseType = &p.config.LicenseType
} }
import_start, err := ec2conn.ImportImage(params) var import_start *ec2.ImportImageOutput
err = retry.Config{
Tries: 11,
RetryDelay: (&retry.Backoff{InitialBackoff: 200 * time.Millisecond, MaxBackoff: 30 * time.Second, Multiplier: 2}).Linear,
}.Run(ctx, func(ctx context.Context) error {
import_start, err = ec2conn.ImportImage(params)
return err
})
if err != nil { if err != nil {
return nil, false, false, fmt.Errorf("Failed to start import from s3://%s/%s: %s", p.config.S3Bucket, p.config.S3Key, err) return nil, false, false, fmt.Errorf("Failed to start import from s3://%s/%s: %s", p.config.S3Bucket, p.config.S3Key, err)