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

fix: make container deletion more robust #672

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions internal/provider/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"strings"

"github.com/docker/docker/client"
"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/terraform"
Expand Down Expand Up @@ -134,3 +135,11 @@ func containsIgnorableErrorMessage(errorMsg string, ignorableErrorMessages ...st

return false
}

func alreadyDeleted(err error) bool {
if strings.Contains(err.Error(), "is already in progress") {
return true
}

return client.IsErrNotFound(err)
}
4 changes: 2 additions & 2 deletions internal/provider/resource_docker_container_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,7 @@ func resourceDockerContainerDelete(ctx context.Context, d *schema.ResourceData,

log.Printf("[INFO] Removing Container '%s'", d.Id())
if err := client.ContainerRemove(ctx, d.Id(), removeOpts); err != nil {
if !containsIgnorableErrorMessage(err.Error(), "No such container", "is already in progress") {
if !alreadyDeleted(err) {
return diag.Errorf("Error deleting container %s: %s", d.Id(), err)
}
}
Expand All @@ -902,7 +902,7 @@ func resourceDockerContainerDelete(ctx context.Context, d *schema.ResourceData,
case waitOk := <-waitOkC:
log.Printf("[INFO] Container exited with code [%v]: '%s'", waitOk.StatusCode, d.Id())
case err := <-errorC:
if !containsIgnorableErrorMessage(err.Error(), "No such container", "is already in progress") {
if !alreadyDeleted(err) {
return diag.Errorf("Error waiting for container removal '%s': %s", d.Id(), err)
}
log.Printf("[INFO] Waiting for Container '%s' errord: '%s'", d.Id(), err.Error())
Expand Down