Skip to content

Commit

Permalink
r/aws_chime_voice_connector_group: handle NotFound error on delete
Browse files Browse the repository at this point in the history
The delete operation calls an update when the `connector` argument is configured, which was not handling cases where the group did not exist (deleted out of band). This change prevents this error from propagating back to the user, and instead just removes the resource from state when the group cannot be found during the delete operation.
  • Loading branch information
jar-b committed Jul 19, 2024
1 parent bd92e0e commit 426cff3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .changelog/36774.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_chime_voice_connector_group: Properly handle voice connector groups deleted out of band
```
8 changes: 7 additions & 1 deletion internal/service/chime/voice_connector_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func resourceVoiceConnectorGroupRead(ctx context.Context, d *schema.ResourceData
resp, err = findVoiceConnectorGroupByID(ctx, conn, d.Id())
}

if !d.IsNewResource() && tfresource.NotFound(err) {
if !d.IsNewResource() && errs.IsA[*awstypes.NotFoundException](err) {
log.Printf("[WARN] Chime Voice conector group %s not found", d.Id())
d.SetId("")
return diags
Expand Down Expand Up @@ -147,6 +147,12 @@ func resourceVoiceConnectorGroupDelete(ctx context.Context, d *schema.ResourceDa
conn := meta.(*conns.AWSClient).ChimeSDKVoiceClient(ctx)

if v, ok := d.GetOk("connector"); ok && v.(*schema.Set).Len() > 0 {
// Exit before attempting connector updates if the group does not exist
_, err := findVoiceConnectorGroupByID(ctx, conn, d.Id())
if errs.IsA[*awstypes.NotFoundException](err) {
return diags
}

if err := resourceVoiceConnectorGroupUpdate(ctx, d, meta); err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions internal/service/chime/voice_connector_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
"github.com/hashicorp/terraform-plugin-testing/terraform"
"github.com/hashicorp/terraform-provider-aws/internal/acctest"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/errs"
tfchime "github.com/hashicorp/terraform-provider-aws/internal/service/chime"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
"github.com/hashicorp/terraform-provider-aws/names"
)

Expand Down Expand Up @@ -196,7 +196,7 @@ func testAccCheckVoiceConnectorGroupDestroy(ctx context.Context) resource.TestCh
return tfchime.FindVoiceConnectorGroupByID(ctx, conn, rs.Primary.ID)
})

if tfresource.NotFound(err) {
if errs.IsA[*awstypes.NotFoundException](err) {
continue
}

Expand Down

0 comments on commit 426cff3

Please sign in to comment.