@@ -217,7 +217,7 @@ func (r *ClusterResource) Create(
217
217
stateConf := & retry.StateChangeConf {
218
218
Pending : []string {string (platform .ClusterStatusCREATING ), string (platform .ClusterStatusUPDATING )},
219
219
Target : []string {string (platform .ClusterStatusCREATED ), string (platform .ClusterStatusUPDATEFAILED ), string (platform .ClusterStatusCREATEFAILED )},
220
- Refresh : r . resourceRefreshFunc (ctx , cluster .JSON200 .Id ),
220
+ Refresh : ClusterResourceRefreshFunc (ctx , r . platformClient , r . organizationId , cluster .JSON200 .Id ),
221
221
Timeout : 3 * time .Hour ,
222
222
MinTimeout : 1 * time .Minute ,
223
223
}
@@ -370,7 +370,7 @@ func (r *ClusterResource) Update(
370
370
stateConf := & retry.StateChangeConf {
371
371
Pending : []string {string (platform .ClusterStatusCREATING ), string (platform .ClusterStatusUPDATING )},
372
372
Target : []string {string (platform .ClusterStatusCREATED ), string (platform .ClusterStatusUPDATEFAILED ), string (platform .ClusterStatusCREATEFAILED )},
373
- Refresh : r . resourceRefreshFunc (ctx , cluster .JSON200 .Id ),
373
+ Refresh : ClusterResourceRefreshFunc (ctx , r . platformClient , r . organizationId , cluster .JSON200 .Id ),
374
374
Timeout : 3 * time .Hour ,
375
375
MinTimeout : 1 * time .Minute ,
376
376
}
@@ -441,7 +441,7 @@ func (r *ClusterResource) Delete(
441
441
stateConf := & retry.StateChangeConf {
442
442
Pending : []string {string (platform .ClusterStatusCREATING ), string (platform .ClusterStatusUPDATING ), string (platform .ClusterStatusCREATED ), string (platform .ClusterStatusUPDATEFAILED ), string (platform .ClusterStatusCREATEFAILED )},
443
443
Target : []string {"DELETED" },
444
- Refresh : r . resourceRefreshFunc (ctx , data .Id .ValueString ()),
444
+ Refresh : ClusterResourceRefreshFunc (ctx , r . platformClient , r . organizationId , data .Id .ValueString ()),
445
445
Timeout : 1 * time .Hour ,
446
446
MinTimeout : 30 * time .Second ,
447
447
}
@@ -576,38 +576,3 @@ func validateGcpConfig(ctx context.Context, data *models.ClusterResource) diag.D
576
576
}
577
577
return diags
578
578
}
579
-
580
- // resourceRefreshFunc returns a retry.StateRefreshFunc that polls the platform API for the cluster status
581
- // If the cluster is not found, it returns "DELETED" status
582
- // If the cluster is found, it returns the cluster status
583
- // If there is an error, it returns the error
584
- // WaitForStateContext will keep polling until the target status is reached, the timeout is reached or an err is returned
585
- func (r * ClusterResource ) resourceRefreshFunc (ctx context.Context , clusterId string ) retry.StateRefreshFunc {
586
- return func () (any , string , error ) {
587
- cluster , err := r .platformClient .GetClusterWithResponse (ctx , r .organizationId , clusterId )
588
- if err != nil {
589
- tflog .Error (ctx , "failed to get cluster while polling for cluster 'CREATED' status" , map [string ]interface {}{"error" : err })
590
- return nil , "" , err
591
- }
592
- statusCode , diagnostic := clients .NormalizeAPIError (ctx , cluster .HTTPResponse , cluster .Body )
593
- if statusCode == http .StatusNotFound {
594
- return & platform.Cluster {}, "DELETED" , nil
595
- }
596
- if diagnostic != nil {
597
- return nil , "" , fmt .Errorf ("error getting cluster %s" , diagnostic .Detail ())
598
- }
599
- if cluster != nil && cluster .JSON200 != nil {
600
- switch cluster .JSON200 .Status {
601
- case platform .ClusterStatusCREATED :
602
- return cluster .JSON200 , string (cluster .JSON200 .Status ), nil
603
- case platform .ClusterStatusUPDATEFAILED , platform .ClusterStatusCREATEFAILED :
604
- return cluster .JSON200 , string (cluster .JSON200 .Status ), fmt .Errorf ("cluster mutation failed for cluster '%v'" , cluster .JSON200 .Id )
605
- case platform .ClusterStatusCREATING , platform .ClusterStatusUPDATING :
606
- return cluster .JSON200 , string (cluster .JSON200 .Status ), nil
607
- default :
608
- return cluster .JSON200 , string (cluster .JSON200 .Status ), fmt .Errorf ("unexpected cluster status '%v' for cluster '%v'" , cluster .JSON200 .Status , cluster .JSON200 .Id )
609
- }
610
- }
611
- return nil , "" , fmt .Errorf ("error getting cluster %s" , clusterId )
612
- }
613
- }
0 commit comments