From fe3a1b5011b1b7714acaaa59afce09d84944a6f9 Mon Sep 17 00:00:00 2001 From: nikhil-goenka <70277861+nikhil-goenka@users.noreply.github.com> Date: Tue, 1 Sep 2020 21:19:19 +0530 Subject: [PATCH] resource/aws_lambda_function_event_invoke_config: Prevent unexpected format of function resource error (#14851) Output from acceptance testing: ``` --- PASS: TestAccAWSLambdaFunctionEventInvokeConfig_Qualifier_FunctionName_Arn (55.47s) --- PASS: TestAccAWSLambdaFunctionEventInvokeConfig_basic (55.86s) --- PASS: TestAccAWSLambdaFunctionEventInvokeConfig_disappears_LambdaFunctionEventInvokeConfig (68.54s) --- PASS: TestAccAWSLambdaFunctionEventInvokeConfig_disappears_LambdaFunction (70.08s) --- PASS: TestAccAWSLambdaFunctionEventInvokeConfig_Qualifier_FunctionVersion (72.29s) --- PASS: TestAccAWSLambdaFunctionEventInvokeConfig_Qualifier_Latest (72.77s) --- PASS: TestAccAWSLambdaFunctionEventInvokeConfig_FunctionName_Arn (73.41s) --- PASS: TestAccAWSLambdaFunctionEventInvokeConfig_Qualifier_AliasName (73.64s) --- PASS: TestAccAWSLambdaFunctionEventInvokeConfig_DestinationConfig_Remove (80.41s) --- PASS: TestAccAWSLambdaFunctionEventInvokeConfig_MaximumEventAgeInSeconds (86.06s) --- PASS: TestAccAWSLambdaFunctionEventInvokeConfig_DestinationConfig_Swap (88.02s) --- PASS: TestAccAWSLambdaFunctionEventInvokeConfig_MaximumRetryAttempts (90.44s) --- PASS: TestAccAWSLambdaFunctionEventInvokeConfig_DestinationConfig_OnSuccess_Destination (102.11s) --- PASS: TestAccAWSLambdaFunctionEventInvokeConfig_DestinationConfig_OnFailure_Destination (103.06s) ``` --- ...aws_lambda_function_event_invoke_config.go | 2 +- ...ambda_function_event_invoke_config_test.go | 36 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/aws/resource_aws_lambda_function_event_invoke_config.go b/aws/resource_aws_lambda_function_event_invoke_config.go index f3b33f5269c..5c76740024f 100644 --- a/aws/resource_aws_lambda_function_event_invoke_config.go +++ b/aws/resource_aws_lambda_function_event_invoke_config.go @@ -289,7 +289,7 @@ func resourceAwsLambdaFunctionEventInvokeConfigParseId(id string) (string, strin return id, "", nil } - functionParts := strings.Split(id, ":") + functionParts := strings.Split(function, ":") if len(functionParts) != 2 || functionParts[0] == "" || functionParts[1] == "" { return "", "", fmt.Errorf("unexpected format of function resource (%s), expected name:qualifier", id) diff --git a/aws/resource_aws_lambda_function_event_invoke_config_test.go b/aws/resource_aws_lambda_function_event_invoke_config_test.go index 00bdfb13ad8..f4672398c76 100644 --- a/aws/resource_aws_lambda_function_event_invoke_config_test.go +++ b/aws/resource_aws_lambda_function_event_invoke_config_test.go @@ -261,6 +261,33 @@ func TestAccAWSLambdaFunctionEventInvokeConfig_FunctionName_Arn(t *testing.T) { }) } +func TestAccAWSLambdaFunctionEventInvokeConfig_Qualifier_FunctionName_Arn(t *testing.T) { + rName := acctest.RandomWithPrefix("tf-acc-test") + lambdaFunctionResourceName := "aws_lambda_function.test" + resourceName := "aws_lambda_function_event_invoke_config.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckLambdaFunctionEventInvokeConfigDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSLambdaFunctionEventInvokeConfigQualifierFunctionNameArn(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAwsLambdaFunctionEventInvokeConfigExists(resourceName), + resource.TestCheckResourceAttrPair(resourceName, "function_name", lambdaFunctionResourceName, "arn"), + resource.TestCheckResourceAttr(resourceName, "qualifier", "$LATEST"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func TestAccAWSLambdaFunctionEventInvokeConfig_MaximumEventAgeInSeconds(t *testing.T) { rName := acctest.RandomWithPrefix("tf-acc-test") resourceName := "aws_lambda_function_event_invoke_config.test" @@ -681,6 +708,15 @@ resource "aws_lambda_function_event_invoke_config" "test" { ` } +func testAccAWSLambdaFunctionEventInvokeConfigQualifierFunctionNameArn(rName string) string { + return testAccAWSLambdaFunctionEventInvokeConfigBase(rName) + ` +resource "aws_lambda_function_event_invoke_config" "test" { + function_name = aws_lambda_function.test.arn + qualifier = "$LATEST" +} +` +} + func testAccAWSLambdaFunctionEventInvokeConfigMaximumEventAgeInSeconds(rName string, maximumEventAgeInSeconds int) string { return testAccAWSLambdaFunctionEventInvokeConfigBase(rName) + fmt.Sprintf(` resource "aws_lambda_function_event_invoke_config" "test" {