From 3cdb3f66fb621af7fbded1f19f22c29dcc8b4562 Mon Sep 17 00:00:00 2001 From: Puneeth Nanjundaswamy Date: Fri, 16 Mar 2018 12:49:44 +0100 Subject: [PATCH] allow diabling lambda from being triggered by setting reserved_concurrent_executions to 0 --- aws/resource_aws_lambda_function.go | 12 +++++++----- aws/resource_aws_lambda_function_test.go | 6 +++--- website/docs/r/lambda_function.html.markdown | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/aws/resource_aws_lambda_function.go b/aws/resource_aws_lambda_function.go index 4a355afb810..f947b98ebf8 100644 --- a/aws/resource_aws_lambda_function.go +++ b/aws/resource_aws_lambda_function.go @@ -89,8 +89,10 @@ func resourceAwsLambdaFunction() *schema.Resource { Default: 128, }, "reserved_concurrent_executions": { - Type: schema.TypeInt, - Optional: true, + Type: schema.TypeInt, + Optional: true, + Default: -1, + ValidateFunc: validation.IntAtLeast(-1), }, "role": { Type: schema.TypeString, @@ -409,7 +411,7 @@ func resourceAwsLambdaFunctionCreate(d *schema.ResourceData, meta interface{}) e d.SetId(d.Get("function_name").(string)) - if reservedConcurrentExecutions > 0 { + if reservedConcurrentExecutions >= 0 { log.Printf("[DEBUG] Setting Concurrency to %d for the Lambda Function %s", reservedConcurrentExecutions, functionName) @@ -532,7 +534,7 @@ func resourceAwsLambdaFunctionRead(d *schema.ResourceData, meta interface{}) err if getFunctionOutput.Concurrency != nil { d.Set("reserved_concurrent_executions", getFunctionOutput.Concurrency.ReservedConcurrentExecutions) } else { - d.Set("reserved_concurrent_executions", nil) + d.Set("reserved_concurrent_executions", -1) } return nil @@ -798,7 +800,7 @@ func resourceAwsLambdaFunctionUpdate(d *schema.ResourceData, meta interface{}) e if d.HasChange("reserved_concurrent_executions") { nc := d.Get("reserved_concurrent_executions") - if nc.(int) > 0 { + if nc.(int) >= 0 { log.Printf("[DEBUG] Updating Concurrency to %d for the Lambda Function %s", nc.(int), d.Id()) concurrencyParams := &lambda.PutFunctionConcurrencyInput{ diff --git a/aws/resource_aws_lambda_function_test.go b/aws/resource_aws_lambda_function_test.go index 48cb7161a0a..3e8103cc4c9 100644 --- a/aws/resource_aws_lambda_function_test.go +++ b/aws/resource_aws_lambda_function_test.go @@ -38,7 +38,7 @@ func TestAccAWSLambdaFunction_basic(t *testing.T) { testAccCheckAwsLambdaFunctionExists("aws_lambda_function.lambda_function_test", funcName, &conf), testAccCheckAwsLambdaFunctionName(&conf, funcName), testAccCheckAwsLambdaFunctionArnHasSuffix(&conf, ":"+funcName), - resource.TestCheckResourceAttr("aws_lambda_function.lambda_function_test", "reserved_concurrent_executions", "0"), + resource.TestCheckResourceAttr("aws_lambda_function.lambda_function_test", "reserved_concurrent_executions", "-1"), ), }, }, @@ -101,7 +101,7 @@ func TestAccAWSLambdaFunction_concurrencyCycle(t *testing.T) { testAccCheckAwsLambdaFunctionExists("aws_lambda_function.lambda_function_test", funcName, &conf), testAccCheckAwsLambdaFunctionName(&conf, funcName), testAccCheckAwsLambdaFunctionArnHasSuffix(&conf, ":"+funcName), - resource.TestCheckResourceAttr("aws_lambda_function.lambda_function_test", "reserved_concurrent_executions", "0"), + resource.TestCheckResourceAttr("aws_lambda_function.lambda_function_test", "reserved_concurrent_executions", "-1"), ), }, { @@ -119,7 +119,7 @@ func TestAccAWSLambdaFunction_concurrencyCycle(t *testing.T) { testAccCheckAwsLambdaFunctionExists("aws_lambda_function.lambda_function_test", funcName, &conf), testAccCheckAwsLambdaFunctionName(&conf, funcName), testAccCheckAwsLambdaFunctionArnHasSuffix(&conf, ":"+funcName), - resource.TestCheckResourceAttr("aws_lambda_function.lambda_function_test", "reserved_concurrent_executions", "0"), + resource.TestCheckResourceAttr("aws_lambda_function.lambda_function_test", "reserved_concurrent_executions", "-1"), ), }, }, diff --git a/website/docs/r/lambda_function.html.markdown b/website/docs/r/lambda_function.html.markdown index 6cc69116aba..0f83704c425 100644 --- a/website/docs/r/lambda_function.html.markdown +++ b/website/docs/r/lambda_function.html.markdown @@ -78,7 +78,7 @@ large files efficiently. * `memory_size` - (Optional) Amount of memory in MB your Lambda Function can use at runtime. Defaults to `128`. See [Limits][5] * `runtime` - (Required) See [Runtimes][6] for valid values. * `timeout` - (Optional) The amount of time your Lambda Function has to run in seconds. Defaults to `3`. See [Limits][5] -* `reserved_concurrent_executions` - (Optional) The amount of reserved concurrent executions for this lambda function. Defaults to Unreserved Concurrency Limits. See [Managing Concurrency][9] +* `reserved_concurrent_executions` - (Optional) The amount of reserved concurrent executions for this lambda function. A value of `0` disables lambda from being triggered and `-1` removes any concurrency limitations. Defaults to Unreserved Concurrency Limits `-1`. See [Managing Concurrency][9] * `publish` - (Optional) Whether to publish creation/change as new Lambda Function Version. Defaults to `false`. * `vpc_config` - (Optional) Provide this to allow your function to access your VPC. Fields documented below. See [Lambda in VPC][7] * `environment` - (Optional) The Lambda environment's configuration settings. Fields documented below.