Skip to content

Commit

Permalink
move time-boxed retry logic to AWS SDK GO service client retry handling
Browse files Browse the repository at this point in the history
  • Loading branch information
anGie44 committed Mar 25, 2021
1 parent d34aca9 commit 2201b15
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
10 changes: 10 additions & 0 deletions aws/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,16 @@ func (c *Config) Client() (interface{}, error) {
}
})

// Reference: https://github.com/hashicorp/terraform-provider-aws/issues/17996
client.securityhubconn.Handlers.Retry.PushBack(func(r *request.Request) {
switch r.Operation.Name {
case "EnableOrganizationAdminAccount":
if tfawserr.ErrCodeEquals(r.Error, securityhub.ErrCodeResourceConflictException) {
r.Retryable = aws.Bool(true)
}
}
})

client.storagegatewayconn.Handlers.Retry.PushBack(func(r *request.Request) {
// InvalidGatewayRequestException: The specified gateway proxy network connection is busy.
if isAWSErr(r.Error, storagegateway.ErrCodeInvalidGatewayRequestException, "The specified gateway proxy network connection is busy") {
Expand Down
18 changes: 1 addition & 17 deletions aws/resource_aws_securityhub_organization_admin_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/securityhub"
"github.com/hashicorp/aws-sdk-go-base/tfawserr"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/service/securityhub/finder"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/service/securityhub/waiter"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/tfresource"
)

func resourceAwsSecurityHubOrganizationAdminAccount() *schema.Resource {
Expand Down Expand Up @@ -44,21 +42,7 @@ func resourceAwsSecurityHubOrganizationAdminAccountCreate(d *schema.ResourceData
AdminAccountId: aws.String(adminAccountID),
}

err := resource.Retry(waiter.AdminAccountEnabledTimeout, func() *resource.RetryError {
_, err := conn.EnableOrganizationAdminAccount(input)

if err != nil {
if tfawserr.ErrCodeEquals(err, securityhub.ErrCodeResourceConflictException) {
return resource.RetryableError(err)
}
return resource.NonRetryableError(err)
}
return nil
})

if tfresource.TimedOut(err) {
_, err = conn.EnableOrganizationAdminAccount(input)
}
_, err := conn.EnableOrganizationAdminAccount(input)

if err != nil {
return fmt.Errorf("error enabling Security Hub Organization Admin Account (%s): %w", adminAccountID, err)
Expand Down

0 comments on commit 2201b15

Please sign in to comment.