diff --git a/internal/service/appstream/find.go b/internal/service/appstream/find.go index 11676b7c1a8..ba9ee0e2a61 100644 --- a/internal/service/appstream/find.go +++ b/internal/service/appstream/find.go @@ -131,12 +131,21 @@ func FindUserByUserNameAndAuthType(ctx context.Context, conn *appstream.AppStrea return !lastPage }) + if tfawserr.ErrCodeEquals(err, appstream.ErrCodeResourceNotFoundException) { + return nil, &resource.NotFoundError{ + LastError: err, + LastRequest: input, + } + } if err != nil { return nil, err } if result == nil { - return nil, nil + return nil, &resource.NotFoundError{ + Message: "Empty result", + LastRequest: input, + } } return result, nil diff --git a/internal/service/appstream/status.go b/internal/service/appstream/status.go index 21fa7af46da..4d49f63a737 100644 --- a/internal/service/appstream/status.go +++ b/internal/service/appstream/status.go @@ -6,6 +6,7 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/appstream" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-provider-aws/internal/tfresource" ) //statusStackState fetches the fleet and its state @@ -63,12 +64,12 @@ func statusUserAvailable(ctx context.Context, conn *appstream.AppStream, usernam return func() (interface{}, string, error) { user, err := FindUserByUserNameAndAuthType(ctx, conn, username, authType) - if err != nil { - return nil, "Unknown", err + if tfresource.NotFound(err) { + return nil, "", nil } - if user == nil { - return user, "NotFound", nil + if err != nil { + return nil, "", err } return user, "AVAILABLE", nil diff --git a/internal/service/appstream/user.go b/internal/service/appstream/user.go index 29957806a67..c3030d1e124 100644 --- a/internal/service/appstream/user.go +++ b/internal/service/appstream/user.go @@ -14,6 +14,7 @@ import ( "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" + "github.com/hashicorp/terraform-provider-aws/internal/tfresource" ) func ResourceUser() *schema.Resource { @@ -143,16 +144,14 @@ func resourceUserRead(ctx context.Context, d *schema.ResourceData, meta interfac } user, err := FindUserByUserNameAndAuthType(ctx, conn, userName, authType) - - if err != nil { - return diag.FromErr(fmt.Errorf("error reading Appstream User (%s): %w", d.Id(), err)) - } - - if !d.IsNewResource() && user == nil { + if tfresource.NotFound(err) && !d.IsNewResource() { log.Printf("[WARN] AppStream User (%s) not found, removing from state", d.Id()) d.SetId("") return nil } + if err != nil { + return diag.FromErr(fmt.Errorf("error reading AppStream User (%s): %w", d.Id(), err)) + } d.Set("arn", user.Arn) d.Set("authentication_type", user.AuthenticationType) @@ -172,7 +171,7 @@ func resourceUserUpdate(ctx context.Context, d *schema.ResourceData, meta interf userName, authType, err := DecodeUserID(d.Id()) if err != nil { - return diag.FromErr(fmt.Errorf("error decoding id AppStream User (%s): %w", d.Id(), err)) + return diag.FromErr(fmt.Errorf("error decoding AppStream User ID (%s): %w", d.Id(), err)) } if d.HasChange("enabled") { diff --git a/internal/service/appstream/wait.go b/internal/service/appstream/wait.go index 490261a0eb7..14f4e8eb743 100644 --- a/internal/service/appstream/wait.go +++ b/internal/service/appstream/wait.go @@ -169,7 +169,6 @@ func waitImageBuilderStateDeleted(ctx context.Context, conn *appstream.AppStream // waitUserAvailable waits for a user be available func waitUserAvailable(ctx context.Context, conn *appstream.AppStream, username, authType string) (*appstream.User, error) { stateConf := &resource.StateChangeConf{ - Pending: []string{"NotFound"}, Target: []string{"AVAILABLE"}, Refresh: statusUserAvailable(ctx, conn, username, authType), Timeout: userOperationTimeout,