Skip to content

Commit

Permalink
test: Introduces shared cluster resource for running search index tes…
Browse files Browse the repository at this point in the history
…ts (#2086)

* test: Introduces shared cluster resource for running search index tests

* adjust logic of check destroy for search index as this check is now called instantly after delete is called

* extract constants
  • Loading branch information
AgustinBettati committed Mar 27, 2024
1 parent 03b0efd commit 01f585c
Show file tree
Hide file tree
Showing 7 changed files with 227 additions and 109 deletions.
5 changes: 5 additions & 0 deletions internal/common/constant/cloud_region.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package constant

const (
UsWest2 = "US_WEST_2"
)
5 changes: 5 additions & 0 deletions internal/common/constant/instance_size.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package constant

const (
M10 = "M10"
)
42 changes: 24 additions & 18 deletions internal/service/advancedcluster/resource_advanced_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,15 +424,7 @@ func resourceCreate(ctx context.Context, d *schema.ResourceData, meta any) diag.
}

timeout := d.Timeout(schema.TimeoutCreate)
stateConf := &retry.StateChangeConf{
Pending: []string{"CREATING", "UPDATING", "REPAIRING", "REPEATING", "PENDING"},
Target: []string{"IDLE"},
Refresh: resourceRefreshFunc(ctx, d.Get("name").(string), projectID, connV2),
Timeout: timeout,
MinTimeout: 1 * time.Minute,
Delay: 3 * time.Minute,
}

stateConf := CreateStateChangeConfig(ctx, connV2, projectID, d.Get("name").(string), timeout)
_, err = stateConf.WaitForStateContext(ctx)
if err != nil {
return diag.FromErr(fmt.Errorf(errorCreate, err))
Expand Down Expand Up @@ -467,6 +459,17 @@ func resourceCreate(ctx context.Context, d *schema.ResourceData, meta any) diag.
return resourceRead(ctx, d, meta)
}

func CreateStateChangeConfig(ctx context.Context, connV2 *admin.APIClient, projectID, name string, timeout time.Duration) retry.StateChangeConf {
return retry.StateChangeConf{
Pending: []string{"CREATING", "UPDATING", "REPAIRING", "REPEATING", "PENDING"},
Target: []string{"IDLE"},
Refresh: resourceRefreshFunc(ctx, name, projectID, connV2),
Timeout: timeout,
MinTimeout: 1 * time.Minute,
Delay: 3 * time.Minute,
}
}

func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
connV2 := meta.(*config.MongoDBClient).AtlasV2
ids := conversion.DecodeStateID(d.Id())
Expand Down Expand Up @@ -763,15 +766,7 @@ func resourceDelete(ctx context.Context, d *schema.ResourceData, meta any) diag.

log.Println("[INFO] Waiting for MongoDB ClusterAdvanced to be destroyed")

stateConf := &retry.StateChangeConf{
Pending: []string{"IDLE", "CREATING", "UPDATING", "REPAIRING", "DELETING"},
Target: []string{"DELETED"},
Refresh: resourceRefreshFunc(ctx, clusterName, projectID, connV2),
Timeout: d.Timeout(schema.TimeoutDelete),
MinTimeout: 30 * time.Second,
Delay: 1 * time.Minute, // Wait 30 secs before starting
}

stateConf := DeleteStateChangeConfig(ctx, connV2, projectID, clusterName, d.Timeout(schema.TimeoutDelete))
// Wait, catching any errors
_, err = stateConf.WaitForStateContext(ctx)
if err != nil {
Expand All @@ -781,6 +776,17 @@ func resourceDelete(ctx context.Context, d *schema.ResourceData, meta any) diag.
return nil
}

func DeleteStateChangeConfig(ctx context.Context, connV2 *admin.APIClient, projectID, name string, timeout time.Duration) retry.StateChangeConf {
return retry.StateChangeConf{
Pending: []string{"IDLE", "CREATING", "UPDATING", "REPAIRING", "DELETING"},
Target: []string{"DELETED"},
Refresh: resourceRefreshFunc(ctx, name, projectID, connV2),
Timeout: timeout,
MinTimeout: 30 * time.Second,
Delay: 1 * time.Minute,
}
}

func resourceImport(ctx context.Context, d *schema.ResourceData, meta any) ([]*schema.ResourceData, error) {
connV2 := meta.(*config.MongoDBClient).AtlasV2

Expand Down

0 comments on commit 01f585c

Please sign in to comment.