Skip to content

Commit

Permalink
Fix review comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
ewbankkit committed Apr 23, 2021
1 parent e3822b4 commit adececc
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
2 changes: 2 additions & 0 deletions aws/internal/service/lambda/waiter/waiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ const (
LambdaFunctionPublishTimeout = 5 * time.Minute
LambdaFunctionPutConcurrencyTimeout = 1 * time.Minute
LambdaFunctionExtraThrottlingTimeout = 9 * time.Minute

EventSourceMappingPropagationTimeout = 5 * time.Minute
)

func EventSourceMappingCreate(conn *lambda.Lambda, id string) (*lambda.EventSourceMappingConfiguration, error) {
Expand Down
7 changes: 4 additions & 3 deletions aws/resource_aws_lambda_event_source_mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
iamwaiter "github.com/terraform-providers/terraform-provider-aws/aws/internal/service/iam/waiter"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/service/lambda/finder"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/service/lambda/waiter"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/tfresource"
Expand Down Expand Up @@ -253,7 +254,7 @@ func resourceAwsLambdaEventSourceMappingCreate(d *schema.ResourceData, meta inte
// retry
var eventSourceMappingConfiguration *lambda.EventSourceMappingConfiguration
var err error
err = resource.Retry(5*time.Minute, func() *resource.RetryError {
err = resource.Retry(iamwaiter.PropagationTimeout, func() *resource.RetryError {
eventSourceMappingConfiguration, err = conn.CreateEventSourceMapping(input)

if tfawserr.ErrCodeEquals(err, lambda.ErrCodeInvalidParameterValueException) {
Expand Down Expand Up @@ -347,7 +348,7 @@ func resourceAwsLambdaEventSourceMappingDelete(d *schema.ResourceData, meta inte
UUID: aws.String(d.Id()),
}

err := resource.Retry(5*time.Minute, func() *resource.RetryError {
err := resource.Retry(waiter.EventSourceMappingPropagationTimeout, func() *resource.RetryError {
_, err := conn.DeleteEventSourceMapping(input)

if tfawserr.ErrCodeEquals(err, lambda.ErrCodeResourceNotFoundException) {
Expand Down Expand Up @@ -431,7 +432,7 @@ func resourceAwsLambdaEventSourceMappingUpdate(d *schema.ResourceData, meta inte
input.ParallelizationFactor = aws.Int64(int64(d.Get("parallelization_factor").(int)))
}

err := resource.Retry(5*time.Minute, func() *resource.RetryError {
err := resource.Retry(waiter.EventSourceMappingPropagationTimeout, func() *resource.RetryError {
_, err := conn.UpdateEventSourceMapping(input)

if tfawserr.ErrCodeEquals(err, lambda.ErrCodeInvalidParameterValueException) {
Expand Down
8 changes: 4 additions & 4 deletions aws/resource_aws_lambda_event_source_mapping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ func TestAccAWSLambdaEventSourceMapping_MSK(t *testing.T) {

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ErrorCheck: testAccErrorCheck(t, lambda.EndpointsID),
ErrorCheck: testAccErrorCheck(t, lambda.EndpointsID, "kafka"), //using kafka.EndpointsID will import kafka and make linters sad
Providers: testAccProviders,
CheckDestroy: testAccCheckLambdaEventSourceMappingDestroy,
Steps: []resource.TestStep{
Expand Down Expand Up @@ -892,7 +892,7 @@ func testAccCheckLambdaEventSourceMappingDestroy(s *terraform.State) error {
}

if err != nil {
return err
return fmt.Errorf("error reading Lambda Event Source Mapping (%s): %w", rs.Primary.ID, err)
}

return fmt.Errorf("Lambda Event Source Mapping %s still exists", rs.Primary.ID)
Expand All @@ -907,11 +907,11 @@ func testAccCheckAwsLambdaEventSourceMappingExists(n string, v *lambda.EventSour
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Not found: %s", n)
return fmt.Errorf(" Lambda Event Source Mapping resource not found: %s", n)
}

if rs.Primary.ID == "" {
return fmt.Errorf("no Lambda Event Source Mapping is set")
return fmt.Errorf("no Lambda Event Source Mapping ID is set")
}

conn := testAccProvider.Meta().(*AWSClient).lambdaconn
Expand Down
8 changes: 8 additions & 0 deletions aws/resource_aws_lambda_function_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,20 @@ import (
)

func init() {
RegisterServiceErrorCheckFunc(lambda.EndpointsID, testAccErrorCheckSkipLambda)

resource.AddTestSweepers("aws_lambda_function", &resource.Sweeper{
Name: "aws_lambda_function",
F: testSweepLambdaFunctions,
})
}

func testAccErrorCheckSkipLambda(t *testing.T) resource.ErrorCheckFunc {
return testAccErrorCheckSkipMessagesContaining(t,
"InvalidParameterValueException: Unsupported source arn",
)
}

func testSweepLambdaFunctions(region string) error {
client, err := sharedClientForRegion(region)
if err != nil {
Expand Down

0 comments on commit adececc

Please sign in to comment.