Skip to content

Commit

Permalink
Merge pull request #24303 from hashicorp/b-appstream-user-stack-assoc…
Browse files Browse the repository at this point in the history
…iation-panic

r/appstream_user_stack_association: prevent panic during resource read
  • Loading branch information
anGie44 authored Apr 19, 2022
2 parents fda6ea2 + 79dec84 commit e43bce5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .changelog/24303.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_appstream_user_stack_association: Prevent panic during resource read
```
9 changes: 8 additions & 1 deletion internal/service/appstream/user_stack_association.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e43bce5

Please sign in to comment.