diff --git a/.changelog/24303.txt b/.changelog/24303.txt new file mode 100644 index 00000000000..7c718d89d04 --- /dev/null +++ b/.changelog/24303.txt @@ -0,0 +1,3 @@ +```release-note:bug +resource/aws_appstream_user_stack_association: Prevent panic during resource read +``` \ No newline at end of file diff --git a/internal/service/appstream/user_stack_association.go b/internal/service/appstream/user_stack_association.go index 8079a027359..d2d92a282d0 100644 --- a/internal/service/appstream/user_stack_association.go +++ b/internal/service/appstream/user_stack_association.go @@ -109,7 +109,14 @@ func resourceUserStackAssociationRead(ctx context.Context, d *schema.ResourceDat return nil } - if len(resp.UserStackAssociations) == 0 && !d.IsNewResource() { + if err != nil { + return diag.FromErr(fmt.Errorf("error reading AppStream User Stack Association (%s): %w", d.Id(), err)) + } + + if resp == nil || len(resp.UserStackAssociations) == 0 || resp.UserStackAssociations[0] == nil { + if d.IsNewResource() { + return diag.Errorf("error reading AppStream User Stack Association (%s): empty output after creation", d.Id()) + } log.Printf("[WARN] AppStream User Stack Association (%s) not found, removing from state", d.Id()) d.SetId("") return nil