Skip to content

Commit deeb917

Browse files
committed
r/eks_cluster: keep retrying only on the resourceinuse condition
1 parent 7aff343 commit deeb917

File tree

1 file changed

+31
-19
lines changed

1 file changed

+31
-19
lines changed

internal/service/eks/cluster.go

+31-19
Original file line numberDiff line numberDiff line change
@@ -499,40 +499,52 @@ func resourceClusterDelete(d *schema.ResourceData, meta interface{}) error {
499499

500500
log.Printf("[DEBUG] Deleting EKS Cluster: %s", d.Id())
501501

502+
input := &eks.DeleteClusterInput{
503+
Name: aws.String(d.Id()),
504+
}
505+
502506
// If a cluster is scaling up due to load a delete request will fail
503507
// This is a temporary workaround until EKS supports multiple parallel mutating operations
504-
return tfresource.RetryConfigContext(context.TODO(), 0*time.Second, 1*time.Minute, 0*time.Second, 30*time.Second, clusterDeleteRetryTimeout, func() *resource.RetryError {
505-
_, err := conn.DeleteCluster(&eks.DeleteClusterInput{
506-
Name: aws.String(d.Id()),
507-
})
508-
509-
if tfawserr.ErrCodeEquals(err, eks.ErrCodeResourceNotFoundException) {
510-
return nil
511-
}
508+
err := tfresource.RetryConfigContext(context.Background(), 0*time.Second, 1*time.Minute, 0*time.Second, 30*time.Second, clusterDeleteRetryTimeout, func() *resource.RetryError {
509+
var err error
512510

513-
// Sometimes the EKS API returns the ResourceNotFound error in this form:
514-
// ClientException: No cluster found for name: tf-acc-test-0o1f8
515-
if tfawserr.ErrMessageContains(err, eks.ErrCodeClientException, "No cluster found for name:") {
516-
return nil
517-
}
511+
_, err = conn.DeleteCluster(input)
518512

519513
if tfawserr.ErrMessageContains(err, eks.ErrCodeResourceInUseException, "in progress") {
520514
log.Printf("[DEBUG] eks cluster update in progress: %v", err)
521515
return resource.RetryableError(err)
522516
}
523517

524518
if err != nil {
525-
return resource.NonRetryableError(fmt.Errorf("error deleting EKS Cluster (%s): %w", d.Id(), err))
519+
return resource.NonRetryableError(err)
526520
}
527521

528-
_, err = waitClusterDeleted(conn, d.Id(), d.Timeout(schema.TimeoutDelete))
522+
return nil
523+
})
529524

530-
if err != nil {
531-
return resource.NonRetryableError(fmt.Errorf("error waiting for EKS Cluster (%s) to delete: %w", d.Id(), err))
532-
}
525+
if tfresource.TimedOut(err) {
526+
_, err = conn.DeleteCluster(input)
527+
}
533528

529+
if tfawserr.ErrCodeEquals(err, eks.ErrCodeResourceNotFoundException) {
534530
return nil
535-
})
531+
}
532+
533+
// Sometimes the EKS API returns the ResourceNotFound error in this form:
534+
// ClientException: No cluster found for name: tf-acc-test-0o1f8
535+
if tfawserr.ErrMessageContains(err, eks.ErrCodeClientException, "No cluster found for name:") {
536+
return nil
537+
}
538+
539+
if err != nil {
540+
return fmt.Errorf("error deleting EKS Cluster (%s): %w", d.Id(), err)
541+
}
542+
543+
if _, err = waitClusterDeleted(conn, d.Id(), d.Timeout(schema.TimeoutDelete)); err != nil {
544+
return fmt.Errorf("error waiting for EKS Cluster (%s) to delete: %w", d.Id(), err)
545+
}
546+
547+
return nil
536548
}
537549

538550
func expandEksEncryptionConfig(tfList []interface{}) []*eks.EncryptionConfig {

0 commit comments

Comments
 (0)