Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

r/aws_lambda_event_source_mapping: Correct attribute updates #17933

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changelog/17933.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:enhancement
resource/aws_lambda_event_source_mapping: Fix update of `batch_size` for MSK event source mappings
```

```release-note:enhancement
resource/aws_lambda_event_source_mapping: Don't incorrectly update unspecified `maximum_batching_window_in_seconds`, `maximum_record_age_in_seconds` and `maximum_retry_attempts` arguments from their default values
```
45 changes: 45 additions & 0 deletions aws/internal/service/lambda/finder/finder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package finder

import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/lambda"
"github.com/hashicorp/aws-sdk-go-base/tfawserr"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

// EventSourceMappingConfigurationByID returns the event source mapping corresponding to the specified ID.
// Returns NotFoundError if no event source mapping is found.
func EventSourceMappingConfigurationByID(conn *lambda.Lambda, uuid string) (*lambda.EventSourceMappingConfiguration, error) {
input := &lambda.GetEventSourceMappingInput{
UUID: aws.String(uuid),
}

return EventSourceMappingConfiguration(conn, input)
}

// EventSourceMappingConfiguration returns the event source mapping corresponding to the specified input.
// Returns NotFoundError if no event source mapping is found.
func EventSourceMappingConfiguration(conn *lambda.Lambda, input *lambda.GetEventSourceMappingInput) (*lambda.EventSourceMappingConfiguration, error) {
output, err := conn.GetEventSourceMapping(input)

if tfawserr.ErrCodeEquals(err, lambda.ErrCodeResourceNotFoundException) {
return nil, &resource.NotFoundError{
LastError: err,
LastRequest: input,
}
}

if err != nil {
return nil, err
}

// Handle any empty result.
if output == nil {
return nil, &resource.NotFoundError{
Message: "Empty result",
LastRequest: input,
}
}

return output, nil
}
18 changes: 6 additions & 12 deletions aws/internal/service/lambda/waiter/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ package waiter
import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/lambda"
"github.com/hashicorp/aws-sdk-go-base/tfawserr"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/service/lambda/finder"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/tfresource"
)

const (
EventSourceMappingStateCreating = "Creating"
EventSourceMappingStateDeleting = "Deleting"
EventSourceMappingStateDisabled = "Disabled"
EventSourceMappingStateDisabling = "Disabling"
EventSourceMappingStateEnabled = "Enabled"
Expand All @@ -18,24 +20,16 @@ const (

func EventSourceMappingState(conn *lambda.Lambda, id string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
input := &lambda.GetEventSourceMappingInput{
UUID: aws.String(id),
}

output, err := conn.GetEventSourceMapping(input)
eventSourceMappingConfiguration, err := finder.EventSourceMappingConfigurationByID(conn, id)

if tfawserr.ErrCodeEquals(err, lambda.ErrCodeResourceNotFoundException) {
if tfresource.NotFound(err) {
return nil, "", nil
}

if err != nil {
return nil, "", err
}

if output == nil {
return nil, "", nil
}

return output, aws.StringValue(output.State), nil
return eventSourceMappingConfiguration, aws.StringValue(eventSourceMappingConfiguration.State), nil
}
}
20 changes: 20 additions & 0 deletions aws/internal/service/lambda/waiter/waiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ import (
const (
EventSourceMappingCreateTimeout = 10 * time.Minute
EventSourceMappingUpdateTimeout = 10 * time.Minute
EventSourceMappingDeleteTimeout = 5 * time.Minute
LambdaFunctionCreateTimeout = 5 * time.Minute
LambdaFunctionUpdateTimeout = 5 * time.Minute
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 All @@ -41,6 +44,23 @@ func EventSourceMappingCreate(conn *lambda.Lambda, id string) (*lambda.EventSour
return nil, err
}

func EventSourceMappingDelete(conn *lambda.Lambda, id string) (*lambda.EventSourceMappingConfiguration, error) {
stateConf := &resource.StateChangeConf{
Pending: []string{EventSourceMappingStateDeleting},
Target: []string{},
Refresh: EventSourceMappingState(conn, id),
Timeout: EventSourceMappingDeleteTimeout,
}

outputRaw, err := stateConf.WaitForState()

if output, ok := outputRaw.(*lambda.EventSourceMappingConfiguration); ok {
return output, err
}

return nil, err
}

func EventSourceMappingUpdate(conn *lambda.Lambda, id string) (*lambda.EventSourceMappingConfiguration, error) {
stateConf := &resource.StateChangeConf{
Pending: []string{
Expand Down
Loading