From 0eb349449cfd1e0977a91a3c7b2ca35dd0672c63 Mon Sep 17 00:00:00 2001 From: Gabriel Parreiras Date: Wed, 5 May 2021 18:18:31 +0100 Subject: [PATCH 01/10] Add starting_position and starting_position_timestamp for event source mapping --- aws/resource_aws_lambda_event_source_mapping.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/aws/resource_aws_lambda_event_source_mapping.go b/aws/resource_aws_lambda_event_source_mapping.go index 7a5ed056f97..ded39c6bbf1 100644 --- a/aws/resource_aws_lambda_event_source_mapping.go +++ b/aws/resource_aws_lambda_event_source_mapping.go @@ -310,6 +310,7 @@ func resourceAwsLambdaEventSourceMappingRead(d *schema.ResourceData, meta interf d.Set("last_processing_result", eventSourceMappingConfiguration.LastProcessingResult) d.Set("state", eventSourceMappingConfiguration.State) d.Set("state_transition_reason", eventSourceMappingConfiguration.StateTransitionReason) + d.Set("starting_position", eventSourceMappingConfiguration.StartingPosition) d.Set("uuid", eventSourceMappingConfiguration.UUID) d.Set("function_name", eventSourceMappingConfiguration.FunctionArn) d.Set("parallelization_factor", eventSourceMappingConfiguration.ParallelizationFactor) @@ -323,6 +324,10 @@ func resourceAwsLambdaEventSourceMappingRead(d *schema.ResourceData, meta interf return fmt.Errorf("error setting topics: %w", err) } + if aws.StringValue(eventSourceMappingConfiguration.StartingPosition) != nil { + d.Set("starting_position_timestamp", aws.TimeValue(eventSourceMappingConfiguration.StartingPositionTimestamp).Format(time.RFC3339)) + } + state := aws.StringValue(eventSourceMappingConfiguration.State) switch state { From 73376648df248b85a9f657d6d8c20c02f31474c0 Mon Sep 17 00:00:00 2001 From: Gabriel Parreiras Date: Wed, 5 May 2021 21:40:50 +0100 Subject: [PATCH 02/10] Use correct variable name --- aws/resource_aws_lambda_event_source_mapping.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws/resource_aws_lambda_event_source_mapping.go b/aws/resource_aws_lambda_event_source_mapping.go index ded39c6bbf1..d0e3bfc92cc 100644 --- a/aws/resource_aws_lambda_event_source_mapping.go +++ b/aws/resource_aws_lambda_event_source_mapping.go @@ -324,7 +324,7 @@ func resourceAwsLambdaEventSourceMappingRead(d *schema.ResourceData, meta interf return fmt.Errorf("error setting topics: %w", err) } - if aws.StringValue(eventSourceMappingConfiguration.StartingPosition) != nil { + if eventSourceMappingConfiguration.StartingPositionTimestamp != nil { d.Set("starting_position_timestamp", aws.TimeValue(eventSourceMappingConfiguration.StartingPositionTimestamp).Format(time.RFC3339)) } From a29786dc0786909bd3a61b5ef15430a5083a1b6a Mon Sep 17 00:00:00 2001 From: Gabriel Parreiras Date: Wed, 5 May 2021 22:39:23 +0100 Subject: [PATCH 03/10] Set starting_position to null instead of empty, to ensure it's backwards compatible --- aws/resource_aws_lambda_event_source_mapping.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/aws/resource_aws_lambda_event_source_mapping.go b/aws/resource_aws_lambda_event_source_mapping.go index d0e3bfc92cc..74389fd3b8d 100644 --- a/aws/resource_aws_lambda_event_source_mapping.go +++ b/aws/resource_aws_lambda_event_source_mapping.go @@ -310,7 +310,6 @@ func resourceAwsLambdaEventSourceMappingRead(d *schema.ResourceData, meta interf d.Set("last_processing_result", eventSourceMappingConfiguration.LastProcessingResult) d.Set("state", eventSourceMappingConfiguration.State) d.Set("state_transition_reason", eventSourceMappingConfiguration.StateTransitionReason) - d.Set("starting_position", eventSourceMappingConfiguration.StartingPosition) d.Set("uuid", eventSourceMappingConfiguration.UUID) d.Set("function_name", eventSourceMappingConfiguration.FunctionArn) d.Set("parallelization_factor", eventSourceMappingConfiguration.ParallelizationFactor) @@ -324,6 +323,10 @@ func resourceAwsLambdaEventSourceMappingRead(d *schema.ResourceData, meta interf return fmt.Errorf("error setting topics: %w", err) } + if eventSourceMappingConfiguration.StartingPosition != nil { + d.Set("starting_position", eventSourceMappingConfiguration.StartingPosition) + } + if eventSourceMappingConfiguration.StartingPositionTimestamp != nil { d.Set("starting_position_timestamp", aws.TimeValue(eventSourceMappingConfiguration.StartingPositionTimestamp).Format(time.RFC3339)) } From d0431d696042d7510b481b09b6fe8881d9d570e4 Mon Sep 17 00:00:00 2001 From: Gabriel Parreiras Date: Wed, 5 May 2021 22:57:33 +0100 Subject: [PATCH 04/10] Remove note on documentation about replace after import --- website/docs/r/lambda_event_source_mapping.html.markdown | 4 ---- 1 file changed, 4 deletions(-) diff --git a/website/docs/r/lambda_event_source_mapping.html.markdown b/website/docs/r/lambda_event_source_mapping.html.markdown index ca2f3ae1efc..9ffda81bef3 100644 --- a/website/docs/r/lambda_event_source_mapping.html.markdown +++ b/website/docs/r/lambda_event_source_mapping.html.markdown @@ -102,7 +102,3 @@ Lambda event source mappings can be imported using the `UUID` (event source mapp ``` $ terraform import aws_lambda_event_source_mapping.event_source_mapping 12345kxodurf3443 ``` - -~> **Note:** Terraform will recreate the imported resource as AWS does not expose `startingPosition` information for existing Lambda event source mappings. For information about retrieving event source mappings, see [GetEventSourceMapping][3] in the API docs. - -[3]: https://docs.aws.amazon.com/lambda/latest/dg/API_GetEventSourceMapping.html From d54800f34f297cf0fa795bdf0d2749464596204f Mon Sep 17 00:00:00 2001 From: Gabriel Parreiras Date: Wed, 5 May 2021 22:59:48 +0100 Subject: [PATCH 05/10] Update tests to check import of both starting_position and starting_position_timestamp --- ...ce_aws_lambda_event_source_mapping_test.go | 52 +++---------------- 1 file changed, 6 insertions(+), 46 deletions(-) diff --git a/aws/resource_aws_lambda_event_source_mapping_test.go b/aws/resource_aws_lambda_event_source_mapping_test.go index ba1e381210f..ccb4af1ea54 100644 --- a/aws/resource_aws_lambda_event_source_mapping_test.go +++ b/aws/resource_aws_lambda_event_source_mapping_test.go @@ -53,7 +53,7 @@ func TestAccAWSLambdaEventSourceMapping_kinesis_basic(t *testing.T) { ResourceName: resourceName, ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"enabled", "starting_position"}, + ImportStateVerifyIgnore: []string{"enabled"}, }, { Config: testAccAWSLambdaEventSourceMappingConfigUpdate_kinesis(roleName, policyName, attName, streamName, funcName, uFuncName), @@ -106,7 +106,7 @@ func TestAccAWSLambdaEventSourceMapping_kinesis_removeBatchSize(t *testing.T) { ResourceName: resourceName, ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"enabled", "starting_position"}, + ImportStateVerifyIgnore: []string{"enabled"}, }, { Config: testAccAWSLambdaEventSourceMappingConfigUpdate_kinesis_removeBatchSize(roleName, policyName, attName, streamName, funcName, uFuncName), @@ -159,7 +159,7 @@ func TestAccAWSLambdaEventSourceMapping_sqs_basic(t *testing.T) { ResourceName: resourceName, ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"enabled", "starting_position"}, + ImportStateVerifyIgnore: []string{"enabled"}, }, { Config: testAccAWSLambdaEventSourceMappingConfigUpdate_sqs(roleName, policyName, attName, streamName, funcName, uFuncName), @@ -210,7 +210,7 @@ func TestAccAWSLambdaEventSourceMapping_sqs_withFunctionName(t *testing.T) { ResourceName: resourceName, ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"enabled", "starting_position"}, + ImportStateVerifyIgnore: []string{"enabled"}, }, }, }) @@ -241,7 +241,7 @@ func TestAccAWSLambdaEventSourceMapping_SQSBatchWindow(t *testing.T) { ResourceName: resourceName, ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"enabled", "starting_position"}, + ImportStateVerifyIgnore: []string{"enabled"}, }, { Config: testAccAWSLambdaEventSourceMappingConfigSqsWithBatchWindow(rName, batchWindowUpdate), @@ -336,10 +336,6 @@ func TestAccAWSLambdaEventSourceMapping_StartingPositionTimestamp(t *testing.T) ResourceName: resourceName, ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "starting_position", - "starting_position_timestamp", - }, }, }, }) @@ -369,10 +365,6 @@ func TestAccAWSLambdaEventSourceMapping_KinesisBatchWindow(t *testing.T) { ResourceName: resourceName, ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "starting_position", - "starting_position_timestamp", - }, }, { Config: testAccAWSLambdaEventSourceMappingConfigKinesisBatchWindow(rName, batchWindowUpdate), @@ -409,10 +401,6 @@ func TestAccAWSLambdaEventSourceMapping_ParallelizationFactor(t *testing.T) { ResourceName: resourceName, ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "starting_position", - "starting_position_timestamp", - }, }, { Config: testAccAWSLambdaEventSourceMappingConfigKinesisParallelizationFactor(rName, parallelizationFactorUpdate), @@ -449,10 +437,6 @@ func TestAccAWSLambdaEventSourceMapping_MaximumRetryAttempts(t *testing.T) { ResourceName: resourceName, ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "starting_position", - "starting_position_timestamp", - }, }, { Config: testAccAWSLambdaEventSourceMappingConfigKinesisMaximumRetryAttempts(rName, maximumRetryAttemptsUpdate), @@ -489,10 +473,6 @@ func TestAccAWSLambdaEventSourceMapping_MaximumRetryAttemptsZero(t *testing.T) { ResourceName: resourceName, ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "starting_position", - "starting_position_timestamp", - }, }, { Config: testAccAWSLambdaEventSourceMappingConfigKinesisMaximumRetryAttempts(rName, maximumRetryAttemptsUpdate), @@ -536,10 +516,6 @@ func TestAccAWSLambdaEventSourceMapping_MaximumRetryAttemptsNegativeOne(t *testi ResourceName: resourceName, ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "starting_position", - "starting_position_timestamp", - }, }, { Config: testAccAWSLambdaEventSourceMappingConfigKinesisMaximumRetryAttempts(rName, maximumRetryAttemptsUpdate), @@ -583,10 +559,6 @@ func TestAccAWSLambdaEventSourceMapping_MaximumRecordAgeInSeconds(t *testing.T) ResourceName: resourceName, ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "starting_position", - "starting_position_timestamp", - }, }, { Config: testAccAWSLambdaEventSourceMappingConfigKinesisMaximumRecordAgeInSeconds(rName, maximumRecordAgeInSecondsUpdate), @@ -623,10 +595,6 @@ func TestAccAWSLambdaEventSourceMapping_MaximumRecordAgeInSecondsNegativeOne(t * ResourceName: resourceName, ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "starting_position", - "starting_position_timestamp", - }, }, { Config: testAccAWSLambdaEventSourceMappingConfigKinesisMaximumRecordAgeInSeconds(rName, maximumRecordAgeInSecondsUpdate), @@ -663,10 +631,6 @@ func TestAccAWSLambdaEventSourceMapping_BisectBatch(t *testing.T) { ResourceName: resourceName, ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "starting_position", - "starting_position_timestamp", - }, }, { Config: testAccAWSLambdaEventSourceMappingConfigKinesisBisectBatch(rName, bisectBatchUpdate), @@ -708,10 +672,6 @@ func TestAccAWSLambdaEventSourceMapping_KinesisDestinationConfig(t *testing.T) { ResourceName: resourceName, ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "starting_position", - "starting_position_timestamp", - }, }, { Config: testAccAWSLambdaEventSourceMappingConfigKinesisDestinationConfig(rName, streamNameUpdated), @@ -755,7 +715,7 @@ func TestAccAWSLambdaEventSourceMapping_MSK(t *testing.T) { ResourceName: resourceName, ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"enabled", "starting_position"}, + ImportStateVerifyIgnore: []string{"enabled"}, }, { Config: testAccAWSLambdaEventSourceMappingConfigMsk(rName, "9999"), From 8a04f07c10a42c33851ff0fed0ebf9b978121d4a Mon Sep 17 00:00:00 2001 From: Gabriel Parreiras Date: Wed, 5 May 2021 23:00:46 +0100 Subject: [PATCH 06/10] Update MSK test as starting_position is required for that resource --- aws/resource_aws_lambda_event_source_mapping_test.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/aws/resource_aws_lambda_event_source_mapping_test.go b/aws/resource_aws_lambda_event_source_mapping_test.go index ccb4af1ea54..aa3e87c53ef 100644 --- a/aws/resource_aws_lambda_event_source_mapping_test.go +++ b/aws/resource_aws_lambda_event_source_mapping_test.go @@ -706,7 +706,6 @@ func TestAccAWSLambdaEventSourceMapping_MSK(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "batch_size", "100"), resource.TestCheckResourceAttrPair(resourceName, "event_source_arn", eventSourceResourceName, "arn"), testAccCheckResourceAttrRfc3339(resourceName, "last_modified"), - resource.TestCheckNoResourceAttr(resourceName, "starting_position"), resource.TestCheckResourceAttr(resourceName, "topics.#", "1"), resource.TestCheckTypeSetElemAttr(resourceName, "topics.*", "test"), ), @@ -725,7 +724,6 @@ func TestAccAWSLambdaEventSourceMapping_MSK(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "batch_size", "9999"), resource.TestCheckResourceAttrPair(resourceName, "event_source_arn", eventSourceResourceName, "arn"), testAccCheckResourceAttrRfc3339(resourceName, "last_modified"), - resource.TestCheckNoResourceAttr(resourceName, "starting_position"), resource.TestCheckResourceAttr(resourceName, "topics.#", "1"), resource.TestCheckTypeSetElemAttr(resourceName, "topics.*", "test"), ), From 14ba5323f6b134163f0dcd7c6815ed41a35aa165 Mon Sep 17 00:00:00 2001 From: Gabriel Parreiras Date: Thu, 6 May 2021 00:31:30 +0100 Subject: [PATCH 07/10] Add starting_position to MSK test, as it's required --- aws/resource_aws_lambda_event_source_mapping_test.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/aws/resource_aws_lambda_event_source_mapping_test.go b/aws/resource_aws_lambda_event_source_mapping_test.go index aa3e87c53ef..1dbc246c195 100644 --- a/aws/resource_aws_lambda_event_source_mapping_test.go +++ b/aws/resource_aws_lambda_event_source_mapping_test.go @@ -1751,11 +1751,12 @@ resource "aws_lambda_function" "test" { } resource "aws_lambda_event_source_mapping" "test" { - batch_size = %[2]s - event_source_arn = aws_msk_cluster.test.arn - enabled = true - function_name = aws_lambda_function.test.arn - topics = ["test"] + batch_size = %[2]s + event_source_arn = aws_msk_cluster.test.arn + enabled = true + function_name = aws_lambda_function.test.arn + topics = ["test"] + starting_position = "TRIM_HORIZON" depends_on = [aws_iam_policy_attachment.test] } From 2051ebce134c80353e5384a442fde6af2927eed1 Mon Sep 17 00:00:00 2001 From: Gabriel Parreiras Date: Thu, 6 May 2021 00:31:39 +0100 Subject: [PATCH 08/10] Add changelog --- .changelog/19253.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/19253.txt diff --git a/.changelog/19253.txt b/.changelog/19253.txt new file mode 100644 index 00000000000..a781a427e4e --- /dev/null +++ b/.changelog/19253.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/aws_lambda_event_source_mapping: Support reading `starting_position` and `starting_position_timestamp` attributes +``` From 9f43319bb42a54aa1d8eee6910d3f3c97e073a02 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Fri, 7 May 2021 14:12:03 -0400 Subject: [PATCH 09/10] r/aws_lambda_event_source_mapping: No need for nil check when reading 'starting_position'. --- aws/resource_aws_lambda_event_source_mapping.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/aws/resource_aws_lambda_event_source_mapping.go b/aws/resource_aws_lambda_event_source_mapping.go index 74389fd3b8d..c32af92e210 100644 --- a/aws/resource_aws_lambda_event_source_mapping.go +++ b/aws/resource_aws_lambda_event_source_mapping.go @@ -323,12 +323,11 @@ func resourceAwsLambdaEventSourceMappingRead(d *schema.ResourceData, meta interf return fmt.Errorf("error setting topics: %w", err) } - if eventSourceMappingConfiguration.StartingPosition != nil { - d.Set("starting_position", eventSourceMappingConfiguration.StartingPosition) - } - + d.Set("starting_position", eventSourceMappingConfiguration.StartingPosition) if eventSourceMappingConfiguration.StartingPositionTimestamp != nil { d.Set("starting_position_timestamp", aws.TimeValue(eventSourceMappingConfiguration.StartingPositionTimestamp).Format(time.RFC3339)) + } else { + d.Set("starting_position_timestamp", nil) } state := aws.StringValue(eventSourceMappingConfiguration.State) From 8d3e1b3fc66431f5898f50d11f94eb1ac035ccf8 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Fri, 7 May 2021 17:14:57 -0400 Subject: [PATCH 10/10] r/aws_lambda_event_source_mapping: Simplify acceptance test configuration and add DynamoDB test. --- ...ce_aws_lambda_event_source_mapping_test.go | 1175 +++++------------ 1 file changed, 338 insertions(+), 837 deletions(-) diff --git a/aws/resource_aws_lambda_event_source_mapping_test.go b/aws/resource_aws_lambda_event_source_mapping_test.go index 1dbc246c195..f3113da2e39 100644 --- a/aws/resource_aws_lambda_event_source_mapping_test.go +++ b/aws/resource_aws_lambda_event_source_mapping_test.go @@ -7,7 +7,6 @@ import ( "time" "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/service/lambda" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" @@ -16,21 +15,13 @@ import ( "github.com/terraform-providers/terraform-provider-aws/aws/internal/tfresource" ) -func TestAccAWSLambdaEventSourceMapping_kinesis_basic(t *testing.T) { +func TestAccAWSLambdaEventSourceMapping_Kinesis_basic(t *testing.T) { var conf lambda.EventSourceMappingConfiguration - - resourceName := "aws_lambda_event_source_mapping.lambda_event_source_mapping_test" - functionResourceName := "aws_lambda_function.lambda_function_test_create" - functionResourceNameUpdated := "aws_lambda_function.lambda_function_test_update" - eventSourceResourceName := "aws_kinesis_stream.kinesis_stream_test" - - rString := acctest.RandString(8) - roleName := fmt.Sprintf("tf_acc_role_lambda_esm_basic_%s", rString) - policyName := fmt.Sprintf("tf_acc_policy_lambda_esm_basic_%s", rString) - attName := fmt.Sprintf("tf_acc_att_lambda_esm_basic_%s", rString) - streamName := fmt.Sprintf("tf_acc_stream_lambda_esm_basic_%s", rString) - funcName := fmt.Sprintf("tf_acc_lambda_esm_basic_%s", rString) - uFuncName := fmt.Sprintf("tf_acc_lambda_esm_basic_updated_%s", rString) + resourceName := "aws_lambda_event_source_mapping.test" + functionResourceName := "aws_lambda_function.test" + functionResourceNameUpdated := "aws_lambda_function.test_update" + eventSourceResourceName := "aws_kinesis_stream.test" + rName := acctest.RandomWithPrefix("tf-acc-test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -39,103 +30,51 @@ func TestAccAWSLambdaEventSourceMapping_kinesis_basic(t *testing.T) { CheckDestroy: testAccCheckLambdaEventSourceMappingDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSLambdaEventSourceMappingConfig_kinesis(roleName, policyName, attName, streamName, funcName, uFuncName), - Check: resource.ComposeTestCheckFunc( - testAccCheckAwsLambdaEventSourceMappingExists(resourceName, &conf), - testAccCheckAWSLambdaEventSourceMappingAttributes(&conf), - testAccCheckResourceAttrRfc3339(resourceName, "last_modified"), - resource.TestCheckResourceAttrPair(resourceName, "function_name", functionResourceName, "arn"), - resource.TestCheckResourceAttrPair(resourceName, "function_arn", functionResourceName, "arn"), - resource.TestCheckResourceAttrPair(resourceName, "event_source_arn", eventSourceResourceName, "arn"), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"enabled"}, - }, - { - Config: testAccAWSLambdaEventSourceMappingConfigUpdate_kinesis(roleName, policyName, attName, streamName, funcName, uFuncName), + Config: testAccAWSLambdaEventSourceMappingConfigKinesisBatchSize(rName, "100"), Check: resource.ComposeTestCheckFunc( testAccCheckAwsLambdaEventSourceMappingExists(resourceName, &conf), - resource.TestCheckResourceAttr(resourceName, "batch_size", strconv.Itoa(200)), - resource.TestCheckResourceAttr(resourceName, "enabled", strconv.FormatBool(false)), - resource.TestCheckResourceAttrPair(resourceName, "function_name", functionResourceNameUpdated, "arn"), - resource.TestCheckResourceAttrPair(resourceName, "function_arn", functionResourceNameUpdated, "arn"), + resource.TestCheckResourceAttr(resourceName, "batch_size", "100"), + resource.TestCheckResourceAttr(resourceName, "enabled", "true"), resource.TestCheckResourceAttrPair(resourceName, "event_source_arn", eventSourceResourceName, "arn"), - resource.TestCheckResourceAttr(resourceName, "starting_position", "TRIM_HORIZON"), - resource.TestCheckResourceAttr(resourceName, "topics.#", "0"), + resource.TestCheckResourceAttrPair(resourceName, "function_arn", functionResourceName, "arn"), + resource.TestCheckResourceAttrPair(resourceName, "function_name", functionResourceName, "arn"), + testAccCheckResourceAttrRfc3339(resourceName, "last_modified"), ), }, - }, - }) -} - -func TestAccAWSLambdaEventSourceMapping_kinesis_removeBatchSize(t *testing.T) { - // batch_size became optional. Ensure that if the user supplies the default - // value, but then moves to not providing the value, that we don't consider this - // a diff. - - var conf lambda.EventSourceMappingConfiguration - - resourceName := "aws_lambda_event_source_mapping.lambda_event_source_mapping_test" - - rString := acctest.RandString(8) - roleName := fmt.Sprintf("tf_acc_role_lambda_esm_basic_%s", rString) - policyName := fmt.Sprintf("tf_acc_policy_lambda_esm_basic_%s", rString) - attName := fmt.Sprintf("tf_acc_att_lambda_esm_basic_%s", rString) - streamName := fmt.Sprintf("tf_acc_stream_lambda_esm_basic_%s", rString) - funcName := fmt.Sprintf("tf_acc_lambda_esm_basic_%s", rString) - uFuncName := fmt.Sprintf("tf_acc_lambda_esm_basic_updated_%s", rString) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - ErrorCheck: testAccErrorCheck(t, lambda.EndpointsID), - Providers: testAccProviders, - CheckDestroy: testAccCheckLambdaEventSourceMappingDestroy, - Steps: []resource.TestStep{ + // batch_size became optional. Ensure that if the user supplies the default + // value, but then moves to not providing the value, that we don't consider this + // a diff. { - Config: testAccAWSLambdaEventSourceMappingConfig_kinesis(roleName, policyName, attName, streamName, funcName, uFuncName), - Check: resource.ComposeTestCheckFunc( - testAccCheckAwsLambdaEventSourceMappingExists(resourceName, &conf), - testAccCheckAWSLambdaEventSourceMappingAttributes(&conf), - ), + PlanOnly: true, + Config: testAccAWSLambdaEventSourceMappingConfigKinesisBatchSize(rName, "null"), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"enabled"}, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, }, { - Config: testAccAWSLambdaEventSourceMappingConfigUpdate_kinesis_removeBatchSize(roleName, policyName, attName, streamName, funcName, uFuncName), + Config: testAccAWSLambdaEventSourceMappingConfigKinesisUpdateFunctionName(rName), Check: resource.ComposeTestCheckFunc( testAccCheckAwsLambdaEventSourceMappingExists(resourceName, &conf), - resource.TestCheckResourceAttr(resourceName, "batch_size", strconv.Itoa(100)), - resource.TestCheckResourceAttr(resourceName, "enabled", strconv.FormatBool(true)), - resource.TestCheckResourceAttr(resourceName, "starting_position", "TRIM_HORIZON"), + resource.TestCheckResourceAttr(resourceName, "batch_size", "200"), + resource.TestCheckResourceAttr(resourceName, "enabled", "false"), + resource.TestCheckResourceAttrPair(resourceName, "event_source_arn", eventSourceResourceName, "arn"), + resource.TestCheckResourceAttrPair(resourceName, "function_arn", functionResourceNameUpdated, "arn"), + resource.TestCheckResourceAttrPair(resourceName, "function_name", functionResourceNameUpdated, "arn"), ), }, }, }) } -func TestAccAWSLambdaEventSourceMapping_sqs_basic(t *testing.T) { +func TestAccAWSLambdaEventSourceMapping_SQS_basic(t *testing.T) { var conf lambda.EventSourceMappingConfiguration - - resourceName := "aws_lambda_event_source_mapping.lambda_event_source_mapping_test" - functionResourceName := "aws_lambda_function.lambda_function_test_create" - functionResourceNameUpdated := "aws_lambda_function.lambda_function_test_update" - eventSourceResourceName := "aws_sqs_queue.sqs_queue_test" - - rString := acctest.RandString(8) - roleName := fmt.Sprintf("tf_acc_role_lambda_sqs_basic_%s", rString) - policyName := fmt.Sprintf("tf_acc_policy_lambda_sqs_basic_%s", rString) - attName := fmt.Sprintf("tf_acc_att_lambda_sqs_basic_%s", rString) - streamName := fmt.Sprintf("tf_acc_stream_lambda_sqs_basic_%s", rString) - funcName := fmt.Sprintf("tf_acc_lambda_sqs_basic_%s", rString) - uFuncName := fmt.Sprintf("tf_acc_lambda_sqs_basic_updated_%s", rString) + resourceName := "aws_lambda_event_source_mapping.test" + functionResourceName := "aws_lambda_function.test" + functionResourceNameUpdated := "aws_lambda_function.test_update" + eventSourceResourceName := "aws_sqs_queue.test" + rName := acctest.RandomWithPrefix("tf-acc-test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -144,51 +83,51 @@ func TestAccAWSLambdaEventSourceMapping_sqs_basic(t *testing.T) { CheckDestroy: testAccCheckLambdaEventSourceMappingDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSLambdaEventSourceMappingConfig_sqs(roleName, policyName, attName, streamName, funcName, uFuncName), + Config: testAccAWSLambdaEventSourceMappingConfigSqsBatchSize(rName, "10"), Check: resource.ComposeTestCheckFunc( testAccCheckAwsLambdaEventSourceMappingExists(resourceName, &conf), - testAccCheckAWSLambdaEventSourceMappingAttributes(&conf), + resource.TestCheckResourceAttr(resourceName, "batch_size", "10"), + resource.TestCheckResourceAttr(resourceName, "enabled", "true"), + resource.TestCheckResourceAttrPair(resourceName, "event_source_arn", eventSourceResourceName, "arn"), resource.TestCheckResourceAttrPair(resourceName, "function_name", functionResourceName, "arn"), resource.TestCheckResourceAttrPair(resourceName, "function_arn", functionResourceName, "arn"), - resource.TestCheckResourceAttrPair(resourceName, "event_source_arn", eventSourceResourceName, "arn"), testAccCheckResourceAttrRfc3339(resourceName, "last_modified"), - resource.TestCheckNoResourceAttr(resourceName, "starting_position"), ), }, + // batch_size became optional. Ensure that if the user supplies the default + // value, but then moves to not providing the value, that we don't consider this + // a diff. + { + PlanOnly: true, + Config: testAccAWSLambdaEventSourceMappingConfigSqsBatchSize(rName, "null"), + }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"enabled"}, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, }, { - Config: testAccAWSLambdaEventSourceMappingConfigUpdate_sqs(roleName, policyName, attName, streamName, funcName, uFuncName), + Config: testAccAWSLambdaEventSourceMappingConfigSqsUpdateFunctionName(rName), Check: resource.ComposeTestCheckFunc( testAccCheckAwsLambdaEventSourceMappingExists(resourceName, &conf), - resource.TestCheckResourceAttr(resourceName, "batch_size", strconv.Itoa(5)), - resource.TestCheckResourceAttr(resourceName, "enabled", strconv.FormatBool(false)), + resource.TestCheckResourceAttr(resourceName, "batch_size", "5"), + resource.TestCheckResourceAttr(resourceName, "enabled", "false"), + resource.TestCheckResourceAttrPair(resourceName, "event_source_arn", eventSourceResourceName, "arn"), resource.TestCheckResourceAttrPair(resourceName, "function_name", functionResourceNameUpdated, "arn"), resource.TestCheckResourceAttrPair(resourceName, "function_arn", functionResourceNameUpdated, "arn"), - resource.TestCheckResourceAttrPair(resourceName, "event_source_arn", eventSourceResourceName, "arn"), - resource.TestCheckNoResourceAttr(resourceName, "starting_position"), + testAccCheckResourceAttrRfc3339(resourceName, "last_modified"), ), }, }, }) } -func TestAccAWSLambdaEventSourceMapping_sqs_withFunctionName(t *testing.T) { +func TestAccAWSLambdaEventSourceMapping_DynamoDB_basic(t *testing.T) { var conf lambda.EventSourceMappingConfiguration - - resourceName := "aws_lambda_event_source_mapping.lambda_event_source_mapping_test" - functionResourceName := "aws_lambda_function.lambda_function_test_create" - - rString := acctest.RandString(8) - roleName := fmt.Sprintf("tf_acc_role_lambda_sqs_basic_%s", rString) - policyName := fmt.Sprintf("tf_acc_policy_lambda_sqs_basic_%s", rString) - attName := fmt.Sprintf("tf_acc_att_lambda_sqs_basic_%s", rString) - streamName := fmt.Sprintf("tf_acc_stream_lambda_sqs_basic_%s", rString) - funcName := fmt.Sprintf("tf_acc_lambda_sqs_basic_%s", rString) + resourceName := "aws_lambda_event_source_mapping.test" + functionResourceName := "aws_lambda_function.test" + eventSourceResourceName := "aws_dynamodb_table.test" + rName := acctest.RandomWithPrefix("tf-acc-test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -197,28 +136,35 @@ func TestAccAWSLambdaEventSourceMapping_sqs_withFunctionName(t *testing.T) { CheckDestroy: testAccCheckLambdaEventSourceMappingDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSLambdaEventSourceMappingConfig_sqs_testWithFunctionName(roleName, policyName, attName, streamName, funcName), + Config: testAccAWSLambdaEventSourceMappingConfigDynamoDbBatchSize(rName, "100"), Check: resource.ComposeTestCheckFunc( testAccCheckAwsLambdaEventSourceMappingExists(resourceName, &conf), - testAccCheckAWSLambdaEventSourceMappingAttributes(&conf), - resource.TestCheckResourceAttrPair(resourceName, "function_name", functionResourceName, "arn"), + resource.TestCheckResourceAttr(resourceName, "batch_size", "100"), + resource.TestCheckResourceAttr(resourceName, "enabled", "true"), + resource.TestCheckResourceAttrPair(resourceName, "event_source_arn", eventSourceResourceName, "stream_arn"), resource.TestCheckResourceAttrPair(resourceName, "function_arn", functionResourceName, "arn"), - resource.TestCheckNoResourceAttr(resourceName, "starting_position"), + resource.TestCheckResourceAttrPair(resourceName, "function_name", functionResourceName, "arn"), + testAccCheckResourceAttrRfc3339(resourceName, "last_modified"), ), }, + // batch_size became optional. Ensure that if the user supplies the default + // value, but then moves to not providing the value, that we don't consider this + // a diff. + { + PlanOnly: true, + Config: testAccAWSLambdaEventSourceMappingConfigDynamoDbBatchSize(rName, "null"), + }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"enabled"}, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, }, }, }) } -func TestAccAWSLambdaEventSourceMapping_SQSBatchWindow(t *testing.T) { +func TestAccAWSLambdaEventSourceMapping_SQS_BatchWindow(t *testing.T) { var conf lambda.EventSourceMappingConfiguration - rName := acctest.RandomWithPrefix("tf-acc-test") resourceName := "aws_lambda_event_source_mapping.test" batchWindow := int64(0) @@ -231,20 +177,19 @@ func TestAccAWSLambdaEventSourceMapping_SQSBatchWindow(t *testing.T) { CheckDestroy: testAccCheckLambdaEventSourceMappingDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSLambdaEventSourceMappingConfigSqsWithBatchWindow(rName, batchWindow), + Config: testAccAWSLambdaEventSourceMappingConfigSqsBatchWindow(rName, batchWindow), Check: resource.ComposeTestCheckFunc( testAccCheckAwsLambdaEventSourceMappingExists(resourceName, &conf), resource.TestCheckResourceAttr(resourceName, "maximum_batching_window_in_seconds", strconv.Itoa(int(batchWindow))), ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"enabled"}, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, }, { - Config: testAccAWSLambdaEventSourceMappingConfigSqsWithBatchWindow(rName, batchWindowUpdate), + Config: testAccAWSLambdaEventSourceMappingConfigSqsBatchWindow(rName, batchWindowUpdate), Check: resource.ComposeTestCheckFunc( testAccCheckAwsLambdaEventSourceMappingExists(resourceName, &conf), resource.TestCheckResourceAttr(resourceName, "maximum_batching_window_in_seconds", strconv.Itoa(int(batchWindowUpdate))), @@ -256,14 +201,8 @@ func TestAccAWSLambdaEventSourceMapping_SQSBatchWindow(t *testing.T) { func TestAccAWSLambdaEventSourceMapping_disappears(t *testing.T) { var conf lambda.EventSourceMappingConfiguration - - rString := acctest.RandString(8) - roleName := fmt.Sprintf("tf_acc_role_lambda_sqs_import_%s", rString) - policyName := fmt.Sprintf("tf_acc_policy_lambda_sqs_import_%s", rString) - attName := fmt.Sprintf("tf_acc_att_lambda_sqs_import_%s", rString) - streamName := fmt.Sprintf("tf_acc_stream_lambda_sqs_import_%s", rString) - funcName := fmt.Sprintf("tf_acc_lambda_sqs_import_%s", rString) - uFuncName := fmt.Sprintf("tf_acc_lambda_sqs_import_updated_%s", rString) + resourceName := "aws_lambda_event_source_mapping.test" + rName := acctest.RandomWithPrefix("tf-acc-test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -272,10 +211,10 @@ func TestAccAWSLambdaEventSourceMapping_disappears(t *testing.T) { CheckDestroy: testAccCheckLambdaEventSourceMappingDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSLambdaEventSourceMappingConfig_sqs(roleName, policyName, attName, streamName, funcName, uFuncName), + Config: testAccAWSLambdaEventSourceMappingConfigSqsBatchSize(rName, "7"), Check: resource.ComposeTestCheckFunc( - testAccCheckAwsLambdaEventSourceMappingExists("aws_lambda_event_source_mapping.lambda_event_source_mapping_test", &conf), - testAccCheckAWSLambdaEventSourceMappingDisappears(&conf), + testAccCheckAwsLambdaEventSourceMappingExists(resourceName, &conf), + testAccCheckResourceDisappears(testAccProvider, resourceAwsLambdaEventSourceMapping(), resourceName), ), ExpectNonEmptyPlan: true, }, @@ -283,16 +222,10 @@ func TestAccAWSLambdaEventSourceMapping_disappears(t *testing.T) { }) } -func TestAccAWSLambdaEventSourceMapping_changesInEnabledAreDetected(t *testing.T) { +func TestAccAWSLambdaEventSourceMapping_SQS_changesInEnabledAreDetected(t *testing.T) { var conf lambda.EventSourceMappingConfiguration - - rString := acctest.RandString(8) - roleName := fmt.Sprintf("tf_acc_role_lambda_sqs_import_%s", rString) - policyName := fmt.Sprintf("tf_acc_policy_lambda_sqs_import_%s", rString) - attName := fmt.Sprintf("tf_acc_att_lambda_sqs_import_%s", rString) - streamName := fmt.Sprintf("tf_acc_stream_lambda_sqs_import_%s", rString) - funcName := fmt.Sprintf("tf_acc_lambda_sqs_import_%s", rString) - uFuncName := fmt.Sprintf("tf_acc_lambda_sqs_import_updated_%s", rString) + resourceName := "aws_lambda_event_source_mapping.test" + rName := acctest.RandomWithPrefix("tf-acc-test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -301,9 +234,9 @@ func TestAccAWSLambdaEventSourceMapping_changesInEnabledAreDetected(t *testing.T CheckDestroy: testAccCheckLambdaEventSourceMappingDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSLambdaEventSourceMappingConfig_sqs(roleName, policyName, attName, streamName, funcName, uFuncName), + Config: testAccAWSLambdaEventSourceMappingConfigSqsBatchSize(rName, "9"), Check: resource.ComposeTestCheckFunc( - testAccCheckAwsLambdaEventSourceMappingExists("aws_lambda_event_source_mapping.lambda_event_source_mapping_test", &conf), + testAccCheckAwsLambdaEventSourceMappingExists(resourceName, &conf), testAccCheckAWSLambdaEventSourceMappingIsBeingDisabled(&conf), ), ExpectNonEmptyPlan: true, @@ -312,7 +245,7 @@ func TestAccAWSLambdaEventSourceMapping_changesInEnabledAreDetected(t *testing.T }) } -func TestAccAWSLambdaEventSourceMapping_StartingPositionTimestamp(t *testing.T) { +func TestAccAWSLambdaEventSourceMapping_Kinesis_StartingPositionTimestamp(t *testing.T) { var conf lambda.EventSourceMappingConfiguration rName := acctest.RandomWithPrefix("tf-acc-test") resourceName := "aws_lambda_event_source_mapping.test" @@ -341,7 +274,7 @@ func TestAccAWSLambdaEventSourceMapping_StartingPositionTimestamp(t *testing.T) }) } -func TestAccAWSLambdaEventSourceMapping_KinesisBatchWindow(t *testing.T) { +func TestAccAWSLambdaEventSourceMapping_Kinesis_BatchWindow(t *testing.T) { var conf lambda.EventSourceMappingConfiguration rName := acctest.RandomWithPrefix("tf-acc-test") resourceName := "aws_lambda_event_source_mapping.test" @@ -377,7 +310,7 @@ func TestAccAWSLambdaEventSourceMapping_KinesisBatchWindow(t *testing.T) { }) } -func TestAccAWSLambdaEventSourceMapping_ParallelizationFactor(t *testing.T) { +func TestAccAWSLambdaEventSourceMapping_Kinesis_ParallelizationFactor(t *testing.T) { var conf lambda.EventSourceMappingConfiguration rName := acctest.RandomWithPrefix("tf-acc-test") resourceName := "aws_lambda_event_source_mapping.test" @@ -413,7 +346,7 @@ func TestAccAWSLambdaEventSourceMapping_ParallelizationFactor(t *testing.T) { }) } -func TestAccAWSLambdaEventSourceMapping_MaximumRetryAttempts(t *testing.T) { +func TestAccAWSLambdaEventSourceMapping_Kinesis_MaximumRetryAttempts(t *testing.T) { var conf lambda.EventSourceMappingConfiguration rName := acctest.RandomWithPrefix("tf-acc-test") resourceName := "aws_lambda_event_source_mapping.test" @@ -449,7 +382,7 @@ func TestAccAWSLambdaEventSourceMapping_MaximumRetryAttempts(t *testing.T) { }) } -func TestAccAWSLambdaEventSourceMapping_MaximumRetryAttemptsZero(t *testing.T) { +func TestAccAWSLambdaEventSourceMapping_Kinesis_MaximumRetryAttemptsZero(t *testing.T) { var conf lambda.EventSourceMappingConfiguration rName := acctest.RandomWithPrefix("tf-acc-test") resourceName := "aws_lambda_event_source_mapping.test" @@ -492,7 +425,7 @@ func TestAccAWSLambdaEventSourceMapping_MaximumRetryAttemptsZero(t *testing.T) { }) } -func TestAccAWSLambdaEventSourceMapping_MaximumRetryAttemptsNegativeOne(t *testing.T) { +func TestAccAWSLambdaEventSourceMapping_Kinesis_MaximumRetryAttemptsNegativeOne(t *testing.T) { var conf lambda.EventSourceMappingConfiguration rName := acctest.RandomWithPrefix("tf-acc-test") resourceName := "aws_lambda_event_source_mapping.test" @@ -535,7 +468,7 @@ func TestAccAWSLambdaEventSourceMapping_MaximumRetryAttemptsNegativeOne(t *testi }) } -func TestAccAWSLambdaEventSourceMapping_MaximumRecordAgeInSeconds(t *testing.T) { +func TestAccAWSLambdaEventSourceMapping_Kinesis_MaximumRecordAgeInSeconds(t *testing.T) { var conf lambda.EventSourceMappingConfiguration rName := acctest.RandomWithPrefix("tf-acc-test") resourceName := "aws_lambda_event_source_mapping.test" @@ -571,7 +504,7 @@ func TestAccAWSLambdaEventSourceMapping_MaximumRecordAgeInSeconds(t *testing.T) }) } -func TestAccAWSLambdaEventSourceMapping_MaximumRecordAgeInSecondsNegativeOne(t *testing.T) { +func TestAccAWSLambdaEventSourceMapping_Kinesis_MaximumRecordAgeInSecondsNegativeOne(t *testing.T) { var conf lambda.EventSourceMappingConfiguration rName := acctest.RandomWithPrefix("tf-acc-test") resourceName := "aws_lambda_event_source_mapping.test" @@ -607,7 +540,7 @@ func TestAccAWSLambdaEventSourceMapping_MaximumRecordAgeInSecondsNegativeOne(t * }) } -func TestAccAWSLambdaEventSourceMapping_BisectBatch(t *testing.T) { +func TestAccAWSLambdaEventSourceMapping_Kinesis_BisectBatch(t *testing.T) { var conf lambda.EventSourceMappingConfiguration rName := acctest.RandomWithPrefix("tf-acc-test") resourceName := "aws_lambda_event_source_mapping.test" @@ -643,15 +576,11 @@ func TestAccAWSLambdaEventSourceMapping_BisectBatch(t *testing.T) { }) } -func TestAccAWSLambdaEventSourceMapping_KinesisDestinationConfig(t *testing.T) { +func TestAccAWSLambdaEventSourceMapping_Kinesis_DestinationConfig(t *testing.T) { var conf lambda.EventSourceMappingConfiguration rName := acctest.RandomWithPrefix("tf-acc-test") - rString := acctest.RandString(8) - streamName := fmt.Sprintf("tf_acc_stream_dest_config_%s", rString) - streamNameUpdated := fmt.Sprintf("tf_acc_stream_dest_config_updated_%s", rString) - resourceName := "aws_lambda_event_source_mapping.test" - sqsResourceName := "aws_sqs_queue.sqs_queue_test" + snsResourceName := "aws_sns_topic.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -660,12 +589,12 @@ func TestAccAWSLambdaEventSourceMapping_KinesisDestinationConfig(t *testing.T) { CheckDestroy: testAccCheckLambdaEventSourceMappingDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSLambdaEventSourceMappingConfigKinesisDestinationConfig(rName, streamName), + Config: testAccAWSLambdaEventSourceMappingConfigKinesisDestinationConfig(rName, rName), Check: resource.ComposeTestCheckFunc( testAccCheckAwsLambdaEventSourceMappingExists(resourceName, &conf), resource.TestCheckResourceAttr(resourceName, "destination_config.#", "1"), resource.TestCheckResourceAttr(resourceName, "destination_config.0.on_failure.#", "1"), - resource.TestCheckResourceAttrPair(resourceName, "destination_config.0.on_failure.0.destination_arn", sqsResourceName, "arn"), + resource.TestCheckResourceAttrPair(resourceName, "destination_config.0.on_failure.0.destination_arn", snsResourceName, "arn"), ), }, { @@ -674,12 +603,12 @@ func TestAccAWSLambdaEventSourceMapping_KinesisDestinationConfig(t *testing.T) { ImportStateVerify: true, }, { - Config: testAccAWSLambdaEventSourceMappingConfigKinesisDestinationConfig(rName, streamNameUpdated), + Config: testAccAWSLambdaEventSourceMappingConfigKinesisDestinationConfig(rName, rName+"-update"), Check: resource.ComposeTestCheckFunc( testAccCheckAwsLambdaEventSourceMappingExists(resourceName, &conf), resource.TestCheckResourceAttr(resourceName, "destination_config.#", "1"), resource.TestCheckResourceAttr(resourceName, "destination_config.0.on_failure.#", "1"), - resource.TestCheckResourceAttrPair(resourceName, "destination_config.0.on_failure.0.destination_arn", sqsResourceName, "arn"), + resource.TestCheckResourceAttrPair(resourceName, "destination_config.0.on_failure.0.destination_arn", snsResourceName, "arn"), ), }, }, @@ -699,10 +628,9 @@ func TestAccAWSLambdaEventSourceMapping_MSK(t *testing.T) { CheckDestroy: testAccCheckLambdaEventSourceMappingDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSLambdaEventSourceMappingConfigMsk(rName, ""), + Config: testAccAWSLambdaEventSourceMappingConfigMsk(rName, "100"), Check: resource.ComposeTestCheckFunc( testAccCheckAwsLambdaEventSourceMappingExists(resourceName, &v), - testAccCheckAWSLambdaEventSourceMappingAttributes(&v), resource.TestCheckResourceAttr(resourceName, "batch_size", "100"), resource.TestCheckResourceAttrPair(resourceName, "event_source_arn", eventSourceResourceName, "arn"), testAccCheckResourceAttrRfc3339(resourceName, "last_modified"), @@ -710,17 +638,22 @@ func TestAccAWSLambdaEventSourceMapping_MSK(t *testing.T) { resource.TestCheckTypeSetElemAttr(resourceName, "topics.*", "test"), ), }, + // batch_size became optional. Ensure that if the user supplies the default + // value, but then moves to not providing the value, that we don't consider this + // a diff. + { + PlanOnly: true, + Config: testAccAWSLambdaEventSourceMappingConfigMsk(rName, "null"), + }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"enabled"}, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, }, { Config: testAccAWSLambdaEventSourceMappingConfigMsk(rName, "9999"), Check: resource.ComposeTestCheckFunc( testAccCheckAwsLambdaEventSourceMappingExists(resourceName, &v), - testAccCheckAWSLambdaEventSourceMappingAttributes(&v), resource.TestCheckResourceAttr(resourceName, "batch_size", "9999"), resource.TestCheckResourceAttrPair(resourceName, "event_source_arn", eventSourceResourceName, "arn"), testAccCheckResourceAttrRfc3339(resourceName, "last_modified"), @@ -784,57 +717,6 @@ func testAccCheckAWSLambdaEventSourceMappingIsBeingDisabled(conf *lambda.EventSo } } -func testAccCheckAWSLambdaEventSourceMappingDisappears(conf *lambda.EventSourceMappingConfiguration) resource.TestCheckFunc { - return func(s *terraform.State) error { - conn := testAccProvider.Meta().(*AWSClient).lambdaconn - - err := resource.Retry(10*time.Minute, func() *resource.RetryError { - params := &lambda.DeleteEventSourceMappingInput{ - UUID: conf.UUID, - } - _, err := conn.DeleteEventSourceMapping(params) - if err != nil { - cgw, ok := err.(awserr.Error) - if ok { - if cgw.Code() == "ResourceNotFoundException" { - return nil - } - - if cgw.Code() == "ResourceInUseException" { - return resource.RetryableError(fmt.Errorf( - "Waiting for Lambda Event Source Mapping to delete: %v", conf.UUID)) - } - } - return resource.NonRetryableError( - fmt.Errorf("Error deleting Lambda Event Source Mapping: %s", err)) - } - - return nil - }) - - if err != nil { - return err - } - - return resource.Retry(10*time.Minute, func() *resource.RetryError { - params := &lambda.GetEventSourceMappingInput{ - UUID: conf.UUID, - } - _, err = conn.GetEventSourceMapping(params) - if err != nil { - cgw, ok := err.(awserr.Error) - if ok && cgw.Code() == "ResourceNotFoundException" { - return nil - } - return resource.NonRetryableError( - fmt.Errorf("Error getting Lambda Event Source Mapping: %s", err)) - } - return resource.RetryableError(fmt.Errorf( - "Waiting to get Lambda Event Source Mapping: %v", conf.UUID)) - }) - } -} - func testAccCheckLambdaEventSourceMappingDestroy(s *terraform.State) error { conn := testAccProvider.Meta().(*AWSClient).lambdaconn @@ -861,7 +743,6 @@ func testAccCheckLambdaEventSourceMappingDestroy(s *terraform.State) error { } func testAccCheckAwsLambdaEventSourceMappingExists(n string, v *lambda.EventSourceMappingConfiguration) resource.TestCheckFunc { - // Wait for IAM role return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -886,35 +767,21 @@ func testAccCheckAwsLambdaEventSourceMappingExists(n string, v *lambda.EventSour } } -func testAccCheckAWSLambdaEventSourceMappingAttributes(mapping *lambda.EventSourceMappingConfiguration) resource.TestCheckFunc { - return func(s *terraform.State) error { - uuid := *mapping.UUID - if uuid == "" { - return fmt.Errorf("Could not read Lambda event source mapping's UUID") - } - - return nil - } -} - func testAccAWSLambdaEventSourceMappingConfigKinesisBase(rName string) string { return fmt.Sprintf(` resource "aws_iam_role" "test" { - name = %q + name = %[1]q assume_role_policy = <