From af8b029ac8905f3a040ded7f9ac853befbf32586 Mon Sep 17 00:00:00 2001 From: PacoDw <__pm@outlook.com> Date: Tue, 1 Oct 2019 09:59:27 -0500 Subject: [PATCH] fix: added validation to verify if a container was removed and the waiting time was reduced fix: add errorContainerDelete to delete func --- .../resource_mongodbatlas_network_container.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/mongodbatlas/resource_mongodbatlas_network_container.go b/mongodbatlas/resource_mongodbatlas_network_container.go index 5b4780dcf8..37c92ca716 100644 --- a/mongodbatlas/resource_mongodbatlas_network_container.go +++ b/mongodbatlas/resource_mongodbatlas_network_container.go @@ -228,15 +228,15 @@ func resourceMongoDBAtlasNetworkContainerDelete(d *schema.ResourceData, meta int Pending: []string{"provisioned_container"}, Target: []string{"deleted"}, Refresh: resourceNetworkContainerRefreshFunc(d, conn), - Timeout: 3 * time.Hour, - MinTimeout: 60 * time.Second, - Delay: 5 * time.Minute, + Timeout: 1 * time.Hour, + MinTimeout: 10 * time.Second, + Delay: 2 * time.Minute, } // Wait, catching any errors _, err := stateConf.WaitForState() if err != nil { - return fmt.Errorf("error %s", err) + return fmt.Errorf(errorContainerDelete, decodeStateID(d.Id())["container_id"], err) } return nil @@ -285,11 +285,15 @@ func resourceNetworkContainerRefreshFunc(d *schema.ResourceData, client *matlas. containerID := ids["container_id"] var err error - container, _, err := client.Containers.Get(context.Background(), projectID, containerID) + container, res, err := client.Containers.Get(context.Background(), projectID, containerID) + if err != nil { + if res.StatusCode == 404 { + return 42, "deleted", nil + } + return nil, "", err + } if *container.Provisioned && err == nil { return nil, "provisioned_container", nil - } else if err != nil { - return nil, "", err } _, err = client.Containers.Delete(context.Background(), projectID, containerID)