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

Bugfix retry behavior in aws_ssoadmin_managed_policy_attachment for eventual consistency issue #19216

Merged
Show file tree
Hide file tree
Changes from 2 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
13 changes: 7 additions & 6 deletions aws/internal/service/ssoadmin/waiter/waiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ import (
)

const (
AWSSSOAdminAccountAssignmentCreateTimeout = 5 * time.Minute
AWSSSOAdminAccountAssignmentDeleteTimeout = 5 * time.Minute
AWSSSOAdminAccountAssignmentDelay = 5 * time.Second
AWSSSOAdminAccountAssignmentMinTimeout = 3 * time.Second
AWSSSOAdminPermissionSetProvisioningRetryDelay = 5 * time.Second
AWSSSOAdminPermissionSetProvisionTimeout = 10 * time.Minute
AWSSSOAdminAccountAssignmentCreateTimeout = 5 * time.Minute
AWSSSOAdminAccountAssignmentDeleteTimeout = 5 * time.Minute
AWSSSOAdminAccountAssignmentDelay = 5 * time.Second
AWSSSOAdminAccountAssignmentMinTimeout = 3 * time.Second
AWSSSOAdminPermissionSetProvisioningRetryDelay = 5 * time.Second
AWSSSOAdminPermissionSetProvisionTimeout = 10 * time.Minute
AWSSSOAdminManagedPolicyAttachmentPropagationTimeout = 2 * time.Minute
)

func AccountAssignmentCreated(conn *ssoadmin.SSOAdmin, instanceArn, requestID string) (*ssoadmin.AccountAssignmentOperationStatus, error) {
Expand Down
29 changes: 27 additions & 2 deletions aws/resource_aws_ssoadmin_managed_policy_attachment.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ssoadmin"
"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/ssoadmin/finder"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/service/ssoadmin/waiter"
)

func resourceAwsSsoAdminManagedPolicyAttachment() *schema.Resource {
Expand Down Expand Up @@ -63,7 +65,19 @@ func resourceAwsSsoAdminManagedPolicyAttachmentCreate(d *schema.ResourceData, me
PermissionSetArn: aws.String(permissionSetArn),
}

_, err := conn.AttachManagedPolicyToPermissionSet(input)
err := resource.Retry(waiter.AWSSSOAdminManagedPolicyAttachmentPropagationTimeout, func() *resource.RetryError {
_, err := conn.AttachManagedPolicyToPermissionSet(input)
if tfawserr.ErrMessageContains(err, ssoadmin.ErrCodeConflictException, "There is a conflicting operation in process") {
return resource.RetryableError(err)
}

if err != nil {
return resource.NonRetryableError(err)
}

return nil
})

if err != nil {
return fmt.Errorf("error attaching Managed Policy to SSO Permission Set (%s): %w", permissionSetArn, err)
}
Expand Down Expand Up @@ -126,7 +140,18 @@ func resourceAwsSsoAdminManagedPolicyAttachmentDelete(d *schema.ResourceData, me
ManagedPolicyArn: aws.String(managedPolicyArn),
}

_, err = conn.DetachManagedPolicyFromPermissionSet(input)
err = resource.Retry(waiter.AWSSSOAdminManagedPolicyAttachmentPropagationTimeout, func() *resource.RetryError {
_, err = conn.DetachManagedPolicyFromPermissionSet(input)
if tfawserr.ErrMessageContains(err, ssoadmin.ErrCodeConflictException, "There is a conflicting operation in process") {
return resource.RetryableError(err)
}

if err != nil {
return resource.NonRetryableError(err)
}

return nil
})

if err != nil {
if tfawserr.ErrCodeEquals(err, ssoadmin.ErrCodeResourceNotFoundException) {
Expand Down