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

resource/aws_directory_service_directory: Adds retry when directory still has authorized applications #22027

Merged
merged 1 commit into from
Dec 3, 2021
Merged
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
23 changes: 21 additions & 2 deletions internal/service/ds/directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package ds
import (
"fmt"
"log"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/directoryservice"
"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/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
Expand All @@ -16,6 +18,10 @@ import (
"github.com/hashicorp/terraform-provider-aws/internal/verify"
)

const (
directoryApplicationDeauthorizedPropagationTimeout = 2 * time.Minute
)

func ResourceDirectory() *schema.Resource {
return &schema.Resource{
Create: resourceDirectoryCreate,
Expand Down Expand Up @@ -517,10 +523,23 @@ func resourceDirectoryDelete(d *schema.ResourceData, meta interface{}) error {
DirectoryId: aws.String(d.Id()),
}

_, err := conn.DeleteDirectory(input)
err := resource.Retry(directoryApplicationDeauthorizedPropagationTimeout, func() *resource.RetryError {
_, err := conn.DeleteDirectory(input)

if tfawserr.ErrCodeEquals(err, directoryservice.ErrCodeEntityDoesNotExistException) {
return nil
}
if tfawserr.ErrMessageContains(err, directoryservice.ErrCodeClientException, "authorized applications") {
return resource.RetryableError(err)
}
if err != nil {
return resource.NonRetryableError(err)
}

if tfawserr.ErrCodeEquals(err, directoryservice.ErrCodeEntityDoesNotExistException) {
return nil
})
if tfresource.TimedOut(err) {
_, err = conn.DeleteDirectory(input)
}

if err != nil {
Expand Down