Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Introduces shared cluster resource for running search index tests #2086

Merged
merged 4 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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