diff --git a/internal/provider/cluster_resource.go b/internal/provider/cluster_resource.go index 0c04eb1a..19ed81ae 100644 --- a/internal/provider/cluster_resource.go +++ b/internal/provider/cluster_resource.go @@ -22,6 +22,7 @@ import ( "net/http" "regexp" "sort" + "time" "github.com/cockroachdb/cockroach-cloud-sdk-go/pkg/client" "github.com/hashicorp/terraform-plugin-framework/diag" @@ -33,6 +34,11 @@ import ( type clusterResourceType struct{} +const ( + clusterCreateTimeout = time.Hour + clusterUpdateTimeout = time.Hour * 2 +) + func (r clusterResourceType) GetSchema(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return tfsdk.Schema{ MarkdownDescription: "Cluster Resource", @@ -278,7 +284,7 @@ func (r clusterResource) Create(ctx context.Context, req tfsdk.CreateResourceReq return } - err = resource.RetryContext(ctx, CREATE_TIMEOUT, + err = resource.RetryContext(ctx, clusterCreateTimeout, waitForClusterCreatedFunc(ctx, clusterObj.Id, r.provider.service, clusterObj)) if err != nil { resp.Diagnostics.AddError( @@ -415,7 +421,7 @@ func (r clusterResource) Update(ctx context.Context, req tfsdk.UpdateResourceReq return } - err = resource.RetryContext(ctx, CREATE_TIMEOUT, + err = resource.RetryContext(ctx, clusterUpdateTimeout, waitForClusterCreatedFunc(ctx, clusterObj.Id, r.provider.service, clusterObj)) if err != nil { resp.Diagnostics.AddError( @@ -554,7 +560,6 @@ func loadClusterToTerraformState(clusterObj *client.Cluster, state *CockroachClu func waitForClusterCreatedFunc(ctx context.Context, id string, cl client.Service, cluster *client.Cluster) resource.RetryFunc { return func() *resource.RetryError { apiCluster, httpResp, err := cl.GetCluster(ctx, id) - *cluster = *apiCluster if err != nil { if httpResp.StatusCode < http.StatusInternalServerError { return resource.NonRetryableError(fmt.Errorf("error getting cluster: %s", formatAPIErrorMessage(err))) @@ -562,10 +567,11 @@ func waitForClusterCreatedFunc(ctx context.Context, id string, cl client.Service return resource.RetryableError(fmt.Errorf("encountered a server error while reading cluster status - trying again")) } } - if string(cluster.State) == CLUSTERSTATETYPE_CREATED { + *cluster = *apiCluster + if cluster.State == client.CLUSTERSTATETYPE_CREATED { return nil } - if string(cluster.State) == CLUSTERSTATETYPE_CREATION_FAILED { + if cluster.State == client.CLUSTERSTATETYPE_CREATION_FAILED { return resource.NonRetryableError(fmt.Errorf("cluster creation failed")) } return resource.RetryableError(fmt.Errorf("cluster is not ready yet")) diff --git a/internal/provider/models.go b/internal/provider/models.go index d94bdf3a..1616d945 100644 --- a/internal/provider/models.go +++ b/internal/provider/models.go @@ -18,18 +18,14 @@ package provider import ( "fmt" - "time" "github.com/hashicorp/terraform-plugin-framework/types" ) const ( - CockroachAPIKey string = "COCKROACH_API_KEY" - APIServerURLKey string = "COCKROACH_SERVER" - UserAgent string = "terraform-provider-cockroach" - CLUSTERSTATETYPE_CREATED string = "CREATED" - CLUSTERSTATETYPE_CREATION_FAILED string = "CREATION_FAILED" - CREATE_TIMEOUT = 60 * time.Minute + CockroachAPIKey string = "COCKROACH_API_KEY" + APIServerURLKey string = "COCKROACH_SERVER" + UserAgent string = "terraform-provider-cockroach" ) type Region struct { diff --git a/internal/provider/private_endpoint_connection_resource.go b/internal/provider/private_endpoint_connection_resource.go index 97834a0e..35b2ce14 100644 --- a/internal/provider/private_endpoint_connection_resource.go +++ b/internal/provider/private_endpoint_connection_resource.go @@ -35,7 +35,7 @@ type privateEndpointConnectionResourceType struct{} const ( // clusterID:endpointID privateEndpointConnectionIDFmt = "%s:%s" - endpointConnectionCreateTimeout = time.Minute * 5 + endpointConnectionCreateTimeout = time.Minute * 10 ) var privateEndpointConnectionIDRegex = regexp.MustCompile(fmt.Sprintf("^(%s):(.*)$", uuidRegex)) diff --git a/internal/provider/private_endpoint_services_resource.go b/internal/provider/private_endpoint_services_resource.go index 0d3c7606..59e76aba 100644 --- a/internal/provider/private_endpoint_services_resource.go +++ b/internal/provider/private_endpoint_services_resource.go @@ -20,6 +20,7 @@ import ( "context" "fmt" "net/http" + "time" "github.com/cockroachdb/cockroach-cloud-sdk-go/pkg/client" "github.com/hashicorp/terraform-plugin-framework/diag" @@ -31,6 +32,8 @@ import ( type privateEndpointServicesResourceType struct{} +const endpointServicesCreateTimeout = time.Hour + func (n privateEndpointServicesResourceType) GetSchema(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return tfsdk.Schema{ MarkdownDescription: "PrivateEndpointServices contains services that allow for VPC communication, either via PrivateLink (AWS) or Peering (GCP)", @@ -155,7 +158,7 @@ func (n privateEndpointServicesResource) Create(ctx context.Context, req tfsdk.C return } var services client.PrivateEndpointServices - err = resource.RetryContext(ctx, CREATE_TIMEOUT, + err = resource.RetryContext(ctx, endpointServicesCreateTimeout, waitForEndpointServicesCreatedFunc(ctx, cluster.Id, n.provider.service, &services)) if err != nil { resp.Diagnostics.AddError(