Skip to content

Commit

Permalink
resource/aws_lambda_function_event_invoke_config: Prevent unexpected …
Browse files Browse the repository at this point in the history
…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)
```
  • Loading branch information
nikhil-goenka authored Sep 1, 2020
1 parent 509a1e9 commit fe3a1b5
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion aws/resource_aws_lambda_function_event_invoke_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
36 changes: 36 additions & 0 deletions aws/resource_aws_lambda_function_event_invoke_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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" {
Expand Down

0 comments on commit fe3a1b5

Please sign in to comment.