Skip to content

Commit 6995d9c

Browse files
coderGo93Edgar Lopez
andauthored
INTMDB-247: Fixes a bug where it's taking 3 minutes to read a cluster (#530)
* fix: fixes a bug when it's taking long to finish for reading a cluster * deleted delay * added nl * refactor: deleted refresh status in datasource cluster and changed time of delay in endpoint service Co-authored-by: Edgar Lopez <[email protected]>
1 parent 908a03e commit 6995d9c

File tree

4 files changed

+15
-63
lines changed

4 files changed

+15
-63
lines changed

examples/aws-atlas-privatelink/atlas-cluster.tf

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
resource "mongodbatlas_cluster" "cluster-atlas" {
22
project_id = var.atlasprojectid
33
name = "cluster-atlas"
4-
provider_backup_enabled = true
4+
cloud_backup = true
55
auto_scaling_disk_gb_enabled = true
66
mongo_db_major_version = "4.2"
77
cluster_type = "REPLICASET"
@@ -19,9 +19,16 @@ resource "mongodbatlas_cluster" "cluster-atlas" {
1919
disk_size_gb = 10
2020
provider_instance_size_name = "M10"
2121
}
22+
23+
data "mongodbatlas_cluster" "cluster-atlas" {
24+
project_id = var.atlasprojectid
25+
name = mongodbatlas_cluster.cluster-atlas.name
26+
depends_on = [mongodbatlas_privatelink_endpoint_service.atlaseplink]
27+
}
28+
2229
output "atlasclusterstring" {
23-
value = mongodbatlas_cluster.cluster-atlas.connection_strings
30+
value = data.mongodbatlas_cluster.cluster-atlas.connection_strings
2431
}
2532
output "plstring" {
26-
value = lookup(mongodbatlas_cluster.cluster-atlas.connection_strings[0].aws_private_link_srv, aws_vpc_endpoint.ptfe_service.id)
33+
value = lookup(data.mongodbatlas_cluster.cluster-atlas.connection_strings[0].aws_private_link_srv, aws_vpc_endpoint.ptfe_service.id)
2734
}

examples/aws-atlas-privatelink/atlas-pl.tf

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ resource "aws_vpc_endpoint" "ptfe_service" {
1313
}
1414

1515
resource "mongodbatlas_privatelink_endpoint_service" "atlaseplink" {
16-
project_id = mongodbatlas_privatelink_endpoint.atlaspl.project_id
17-
private_link_id = mongodbatlas_privatelink_endpoint.atlaspl.private_link_id
18-
interface_endpoint_id = aws_vpc_endpoint.ptfe_service.id
16+
project_id = mongodbatlas_privatelink_endpoint.atlaspl.project_id
17+
endpoint_service_id = aws_vpc_endpoint.ptfe_service.id
18+
private_link_id = mongodbatlas_privatelink_endpoint.atlaspl.id
19+
provider_name = "AWS"
1920
}

mongodbatlas/data_source_mongodbatlas_cluster.go

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,10 @@ package mongodbatlas
33
import (
44
"context"
55
"fmt"
6-
"log"
76
"net/http"
8-
"time"
97

108
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
11-
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
129
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
13-
"github.com/spf13/cast"
14-
matlas "go.mongodb.org/atlas/mongodbatlas"
1510
)
1611

1712
func dataSourceMongoDBAtlasCluster() *schema.Resource {
@@ -330,25 +325,6 @@ func dataSourceMongoDBAtlasClusterRead(ctx context.Context, d *schema.ResourceDa
330325
return diag.FromErr(fmt.Errorf(errorClusterRead, clusterName, err))
331326
}
332327

333-
if cluster.ProviderSettings != nil && (cast.ToString(cluster.ProviderSettings.ProviderName) == "AWS" ||
334-
cast.ToString(cluster.ProviderSettings.ProviderName) == "AZURE") {
335-
stateConf := &resource.StateChangeConf{
336-
Pending: []string{"PRIVATE_ENDPOINTS_NIL", "PRIVATE_ENDPOINTS_EMPTY"},
337-
Target: []string{"PRIVATE_ENDPOINTS_EXISTS", "NORMAL"},
338-
Refresh: datasourceClusterPrivateEndpointRefreshFunc(clusterName, projectID, conn),
339-
Timeout: 10 * time.Minute,
340-
MinTimeout: 1 * time.Minute,
341-
Delay: 3 * time.Minute,
342-
}
343-
344-
resp, err := stateConf.WaitForStateContext(ctx)
345-
if err != nil {
346-
log.Printf("[ERROR] %v", fmt.Errorf(errorClusterRead, clusterName, err))
347-
} else {
348-
cluster = resp.(*matlas.Cluster)
349-
}
350-
}
351-
352328
if err := d.Set("auto_scaling_disk_gb_enabled", cluster.AutoScaling.DiskGBEnabled); err != nil {
353329
return diag.FromErr(fmt.Errorf(errorClusterSetting, "auto_scaling_disk_gb_enabled", clusterName, err))
354330
}
@@ -458,35 +434,3 @@ func dataSourceMongoDBAtlasClusterRead(ctx context.Context, d *schema.ResourceDa
458434

459435
return nil
460436
}
461-
462-
func datasourceClusterPrivateEndpointRefreshFunc(name, projectID string, client *matlas.Client) resource.StateRefreshFunc {
463-
return func() (interface{}, string, error) {
464-
cluster, resp, err := client.Clusters.Get(context.Background(), projectID, name)
465-
466-
if err != nil && cluster == nil && resp == nil {
467-
return nil, "", err
468-
} else if err != nil {
469-
if resp.StatusCode == 404 {
470-
return "", "DELETED", nil
471-
}
472-
if resp.StatusCode == 503 {
473-
return "", "PENDING", nil
474-
}
475-
return nil, "", err
476-
}
477-
478-
if cluster.ConnectionStrings != nil {
479-
if cluster.ConnectionStrings.PrivateEndpoint == nil {
480-
return cluster, "PRIVATE_ENDPOINTS_NIL", nil
481-
}
482-
if cluster.ConnectionStrings.PrivateEndpoint != nil && len(cluster.ConnectionStrings.PrivateEndpoint) == 0 {
483-
return cluster, "PRIVATE_ENDPOINTS_EMPTY", nil
484-
}
485-
if cluster.ConnectionStrings.PrivateEndpoint != nil && len(cluster.ConnectionStrings.PrivateEndpoint) != 0 {
486-
return cluster, "PRIVATE_ENDPOINTS_EXISTS", nil
487-
}
488-
}
489-
490-
return cluster, "NORMAL", nil
491-
}
492-
}

mongodbatlas/resource_mongodbatlas_privatelink_endpoint_service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func resourceMongoDBAtlasPrivateEndpointServiceLinkCreate(ctx context.Context, d
114114
Refresh: resourceServiceEndpointRefreshFunc(ctx, conn, projectID, providerName, privateLinkID, endpointServiceID),
115115
Timeout: 1 * time.Hour,
116116
MinTimeout: 5 * time.Second,
117-
Delay: 3 * time.Second,
117+
Delay: 5 * time.Minute,
118118
}
119119
// Wait, catching any errors
120120
_, err = stateConf.WaitForStateContext(ctx)

0 commit comments

Comments
 (0)