Skip to content

Commit

Permalink
refactor: deleted refresh status in datasource cluster and changed ti…
Browse files Browse the repository at this point in the history
…me of delay in endpoint service
  • Loading branch information
Edgar Lopez committed Aug 27, 2021
1 parent edd2093 commit 4bd6d8d
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 56 deletions.
55 changes: 0 additions & 55 deletions mongodbatlas/data_source_mongodbatlas_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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))
}
Expand Down Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 4bd6d8d

Please sign in to comment.