From 98e042b126d61d3eac289fbf59bedee3e6fd918d Mon Sep 17 00:00:00 2001 From: Brian Flad Date: Wed, 28 Feb 2018 14:24:18 -0500 Subject: [PATCH] resource/aws_lambda_function: Allow PutFunctionConcurrency retries on creation Also set resource ID before PutFunctionConcurrency --- aws/resource_aws_lambda_function.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/aws/resource_aws_lambda_function.go b/aws/resource_aws_lambda_function.go index 6050df8d806..9ed11a15880 100644 --- a/aws/resource_aws_lambda_function.go +++ b/aws/resource_aws_lambda_function.go @@ -378,6 +378,8 @@ func resourceAwsLambdaFunctionCreate(d *schema.ResourceData, meta interface{}) e return fmt.Errorf("Error creating Lambda function: %s", err) } + d.SetId(d.Get("function_name").(string)) + if reservedConcurrentExecutions > 0 { log.Printf("[DEBUG] Setting Concurrency to %d for the Lambda Function %s", reservedConcurrentExecutions, functionName) @@ -387,14 +389,21 @@ func resourceAwsLambdaFunctionCreate(d *schema.ResourceData, meta interface{}) e ReservedConcurrentExecutions: aws.Int64(int64(reservedConcurrentExecutions)), } - _, err := conn.PutFunctionConcurrency(concurrencyParams) + err := resource.Retry(1*time.Minute, func() *resource.RetryError { + _, err := conn.PutFunctionConcurrency(concurrencyParams) + if err != nil { + if isAWSErr(err, lambda.ErrCodeResourceNotFoundException, "") { + return resource.RetryableError(err) + } + return resource.NonRetryableError(err) + } + return nil + }) if err != nil { return fmt.Errorf("Error setting concurrency for Lambda %s: %s", functionName, err) } } - d.SetId(d.Get("function_name").(string)) - return resourceAwsLambdaFunctionRead(d, meta) }