|
| 1 | +// Copyright (c) HashiCorp, Inc. |
| 2 | +// SPDX-License-Identifier: MPL-2.0 |
| 3 | + |
| 4 | +package events |
| 5 | + |
| 6 | +import ( |
| 7 | + "context" |
| 8 | + |
| 9 | + "github.com/aws/aws-sdk-go-v2/aws" |
| 10 | + "github.com/aws/aws-sdk-go-v2/aws/retry" |
| 11 | + "github.com/aws/aws-sdk-go-v2/service/eventbridge" |
| 12 | + awstypes "github.com/aws/aws-sdk-go-v2/service/eventbridge/types" |
| 13 | + "github.com/hashicorp/terraform-plugin-log/tflog" |
| 14 | + "github.com/hashicorp/terraform-provider-aws/internal/conns" |
| 15 | + "github.com/hashicorp/terraform-provider-aws/internal/errs" |
| 16 | + "github.com/hashicorp/terraform-provider-aws/internal/vcr" |
| 17 | +) |
| 18 | + |
| 19 | +func (p *servicePackage) withExtraOptions(ctx context.Context, config map[string]any) []func(*eventbridge.Options) { |
| 20 | + cfg := *(config["aws_sdkv2_config"].(*aws.Config)) |
| 21 | + |
| 22 | + return []func(*eventbridge.Options){ |
| 23 | + func(o *eventbridge.Options) { |
| 24 | + retryables := []retry.IsErrorRetryable{ |
| 25 | + retry.IsErrorRetryableFunc(func(err error) aws.Ternary { |
| 26 | + if errs.IsAErrorMessageContains[*awstypes.LimitExceededException](err, "The requested resource exceeds the maximum number allowed") { |
| 27 | + return aws.FalseTernary |
| 28 | + } |
| 29 | + return aws.UnknownTernary // Delegate to configured Retryer. |
| 30 | + }), |
| 31 | + } |
| 32 | + // Include go-vcr retryable to prevent generated client retryer from being overridden |
| 33 | + if inContext, ok := conns.FromContext(ctx); ok && inContext.VCREnabled() { |
| 34 | + tflog.Info(ctx, "overriding retry behavior to immediately return VCR errors") |
| 35 | + retryables = append(retryables, vcr.InteractionNotFoundRetryableFunc) |
| 36 | + } |
| 37 | + |
| 38 | + o.Retryer = conns.AddIsErrorRetryables(cfg.Retryer().(aws.RetryerV2), retryables...) |
| 39 | + }, |
| 40 | + } |
| 41 | +} |
0 commit comments