From 229e85e4d4f312097734383ab39536d0e2fbebea Mon Sep 17 00:00:00 2001 From: PacoDw <__pm@outlook.com> Date: Mon, 23 Sep 2019 20:24:51 -0500 Subject: [PATCH 1/3] chore: fixed the disk_size_gb value in network_container_test --- mongodbatlas/resource_mongodbatlas_cluster_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mongodbatlas/resource_mongodbatlas_cluster_test.go b/mongodbatlas/resource_mongodbatlas_cluster_test.go index 922673841d..8f6c982a8c 100644 --- a/mongodbatlas/resource_mongodbatlas_cluster_test.go +++ b/mongodbatlas/resource_mongodbatlas_cluster_test.go @@ -307,7 +307,7 @@ func testAccMongoDBAtlasClusterConfigAWS(projectID, name, backupEnabled string) resource "mongodbatlas_cluster" "test" { project_id = "%s" name = "%s" - disk_size_gb = 40 + disk_size_gb = 100 num_shards = 1 replication_factor = 3 From dd2abbafaf51babe87fe10aad622d748648f0847 Mon Sep 17 00:00:00 2001 From: PacoDw <__pm@outlook.com> Date: Tue, 24 Sep 2019 08:42:07 -0500 Subject: [PATCH 2/3] fix: add refresh func to avoid issues --- ...resource_mongodbatlas_network_container.go | 43 ++++++++++++++++--- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/mongodbatlas/resource_mongodbatlas_network_container.go b/mongodbatlas/resource_mongodbatlas_network_container.go index 1c6d6905a1..5b4780dcf8 100644 --- a/mongodbatlas/resource_mongodbatlas_network_container.go +++ b/mongodbatlas/resource_mongodbatlas_network_container.go @@ -8,7 +8,9 @@ import ( "net/http" "reflect" "strings" + "time" + "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/validation" matlas "github.com/mongodb/go-client-mongodb-atlas/mongodbatlas" @@ -221,14 +223,22 @@ func resourceMongoDBAtlasNetworkContainerUpdate(d *schema.ResourceData, meta int func resourceMongoDBAtlasNetworkContainerDelete(d *schema.ResourceData, meta interface{}) error { //Get client connection. conn := meta.(*matlas.Client) - ids := decodeStateID(d.Id()) - projectID := ids["project_id"] - containerID := ids["container_id"] - _, err := conn.Containers.Delete(context.Background(), projectID, containerID) + stateConf := &resource.StateChangeConf{ + Pending: []string{"provisioned_container"}, + Target: []string{"deleted"}, + Refresh: resourceNetworkContainerRefreshFunc(d, conn), + Timeout: 3 * time.Hour, + MinTimeout: 60 * time.Second, + Delay: 5 * time.Minute, + } + + // Wait, catching any errors + _, err := stateConf.WaitForState() if err != nil { - return fmt.Errorf(errorContainerDelete, containerID, err) + return fmt.Errorf("error %s", err) } + return nil } @@ -267,3 +277,26 @@ func resourceMongoDBAtlasNetworkContainerImportState(d *schema.ResourceData, met } return []*schema.ResourceData{d}, nil } + +func resourceNetworkContainerRefreshFunc(d *schema.ResourceData, client *matlas.Client) resource.StateRefreshFunc { + return func() (interface{}, string, error) { + ids := decodeStateID(d.Id()) + projectID := ids["project_id"] + containerID := ids["container_id"] + + var err error + container, _, err := client.Containers.Get(context.Background(), projectID, containerID) + 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) + if err != nil { + return nil, "provisioned_container", nil + } + + return 42, "deleted", nil + } +} From 0a39f4c5c36867f953ea6700dab29d597967a8a4 Mon Sep 17 00:00:00 2001 From: PacoDw <__pm@outlook.com> Date: Tue, 1 Oct 2019 09:59:27 -0500 Subject: [PATCH 3/3] 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)