From 4bd6d8dfd86640736eb2d682d7ac408b44d222f8 Mon Sep 17 00:00:00 2001 From: Edgar Lopez Date: Thu, 26 Aug 2021 16:16:12 -0600 Subject: [PATCH] refactor: deleted refresh status in datasource cluster and changed time of delay in endpoint service --- .../data_source_mongodbatlas_cluster.go | 55 ------------------- ...ngodbatlas_privatelink_endpoint_service.go | 2 +- 2 files changed, 1 insertion(+), 56 deletions(-) diff --git a/mongodbatlas/data_source_mongodbatlas_cluster.go b/mongodbatlas/data_source_mongodbatlas_cluster.go index 0e39ba984a..f7ab8f4e62 100644 --- a/mongodbatlas/data_source_mongodbatlas_cluster.go +++ b/mongodbatlas/data_source_mongodbatlas_cluster.go @@ -3,15 +3,10 @@ package mongodbatlas import ( "context" "fmt" - "log" "net/http" - "time" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/spf13/cast" - matlas "go.mongodb.org/atlas/mongodbatlas" ) func dataSourceMongoDBAtlasCluster() *schema.Resource { @@ -330,24 +325,6 @@ func dataSourceMongoDBAtlasClusterRead(ctx context.Context, d *schema.ResourceDa return diag.FromErr(fmt.Errorf(errorClusterRead, clusterName, err)) } - if cluster.ProviderSettings != nil && (cast.ToString(cluster.ProviderSettings.ProviderName) == "AWS" || - cast.ToString(cluster.ProviderSettings.ProviderName) == "AZURE") { - stateConf := &resource.StateChangeConf{ - Pending: []string{"PRIVATE_ENDPOINTS_NIL", "PRIVATE_ENDPOINTS_EMPTY"}, - Target: []string{"PRIVATE_ENDPOINTS_EXISTS", "NORMAL"}, - Refresh: datasourceClusterPrivateEndpointRefreshFunc(clusterName, projectID, conn), - Timeout: 10 * time.Minute, - MinTimeout: 5 * time.Second, - } - - resp, err := stateConf.WaitForStateContext(ctx) - if err != nil { - log.Printf("[ERROR] %v", fmt.Errorf(errorClusterRead, clusterName, err)) - } else { - cluster = resp.(*matlas.Cluster) - } - } - if err := d.Set("auto_scaling_disk_gb_enabled", cluster.AutoScaling.DiskGBEnabled); err != nil { return diag.FromErr(fmt.Errorf(errorClusterSetting, "auto_scaling_disk_gb_enabled", clusterName, err)) } @@ -457,35 +434,3 @@ func dataSourceMongoDBAtlasClusterRead(ctx context.Context, d *schema.ResourceDa return nil } - -func datasourceClusterPrivateEndpointRefreshFunc(name, projectID string, client *matlas.Client) resource.StateRefreshFunc { - return func() (interface{}, string, error) { - cluster, resp, err := client.Clusters.Get(context.Background(), projectID, name) - - if err != nil && cluster == nil && resp == nil { - return nil, "", err - } else if err != nil { - if resp.StatusCode == 404 { - return "", "DELETED", nil - } - if resp.StatusCode == 503 { - return "", "PENDING", nil - } - return nil, "", err - } - - if cluster.ConnectionStrings != nil { - if cluster.ConnectionStrings.PrivateEndpoint == nil { - return cluster, "PRIVATE_ENDPOINTS_NIL", nil - } - if cluster.ConnectionStrings.PrivateEndpoint != nil && len(cluster.ConnectionStrings.PrivateEndpoint) == 0 { - return cluster, "PRIVATE_ENDPOINTS_EMPTY", nil - } - if cluster.ConnectionStrings.PrivateEndpoint != nil && len(cluster.ConnectionStrings.PrivateEndpoint) != 0 { - return cluster, "PRIVATE_ENDPOINTS_EXISTS", nil - } - } - - return cluster, "NORMAL", nil - } -} diff --git a/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_service.go b/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_service.go index f436eabddc..3c915a5828 100644 --- a/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_service.go +++ b/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_service.go @@ -114,7 +114,7 @@ func resourceMongoDBAtlasPrivateEndpointServiceLinkCreate(ctx context.Context, d Refresh: resourceServiceEndpointRefreshFunc(ctx, conn, projectID, providerName, privateLinkID, endpointServiceID), Timeout: 1 * time.Hour, MinTimeout: 5 * time.Second, - Delay: 3 * time.Second, + Delay: 5 * time.Minute, } // Wait, catching any errors _, err = stateConf.WaitForStateContext(ctx)