From bfa4a881700c1498cb1b0085aff65c47a13db2b7 Mon Sep 17 00:00:00 2001 From: Chris Marchesi Date: Mon, 14 Dec 2015 11:12:06 -0800 Subject: [PATCH] Retry InvalidParameterValueException errors due to newly created resources --- ...esource_aws_lambda_event_source_mapping.go | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/builtin/providers/aws/resource_aws_lambda_event_source_mapping.go b/builtin/providers/aws/resource_aws_lambda_event_source_mapping.go index 70ca3a01c..4adb3f044 100644 --- a/builtin/providers/aws/resource_aws_lambda_event_source_mapping.go +++ b/builtin/providers/aws/resource_aws_lambda_event_source_mapping.go @@ -3,10 +3,13 @@ package aws import ( "fmt" "log" + "time" "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/service/lambda" + "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/schema" ) @@ -88,14 +91,28 @@ func resourceAwsLambdaEventSourceMappingCreate(d *schema.ResourceData, meta inte Enabled: aws.Bool(d.Get("enabled").(bool)), } - eventSourceMappingConfiguration, err := conn.CreateEventSourceMapping(params) + err := resource.Retry(1*time.Minute, func() error { + eventSourceMappingConfiguration, err := conn.CreateEventSourceMapping(params) + if err != nil { + if awserr, ok := err.(awserr.Error); ok { + if awserr.Code() == "InvalidParameterValueException" { + // Retryable + return awserr + } + } + // Not retryable + return resource.RetryError{Err: err} + } + // No error + d.Set("uuid", eventSourceMappingConfiguration.UUID) + d.SetId(*eventSourceMappingConfiguration.UUID) + return nil + }) + if err != nil { return fmt.Errorf("Error creating Lambda event source mapping: %s", err) } - d.Set("uuid", eventSourceMappingConfiguration.UUID) - d.SetId(*eventSourceMappingConfiguration.UUID) - return resourceAwsLambdaEventSourceMappingRead(d, meta) }