Skip to content

Commit a552b2b

Browse files
committed
fix: respect --timeout flag for all AWS resource deletion waiters
Previously, many AWS resource deletion waiters had hardcoded timeouts that ignored the user-provided --timeout flag. This change: - Adds GetTimeoutWithDefault() helper to BaseAwsResource - Defines default timeout constants in each resource's types file - Updates all waiters to use the configured timeout or default Affected resources: - RDS instances and clusters (was 1 min / 15 min, now 30 min default) - Elasticache (was 15 min) - ECS Services (was 15 min) - ASG (was 5 min) - EC2 instances (was 15 min) - EC2 Network Interfaces (was 5 min) - EC2 VPC (was 5 min) - EBS volumes (was 5 min) - EKS clusters, node groups, fargate profiles (was 15 min) - ELBv2 (was 15 min) - Redshift (was 5 min) - Backup Vault (was 1 min) - OpenSearch (was 5 min) - NAT Gateway (was 5 min) Fixes #964
1 parent 118cd44 commit a552b2b

31 files changed

+85
-47
lines changed

aws/resources/asg.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package resources
22

33
import (
44
"context"
5-
"time"
65

76
"github.com/aws/aws-sdk-go-v2/aws"
87
"github.com/aws/aws-sdk-go-v2/service/autoscaling"
@@ -72,7 +71,7 @@ func (ag *ASGroups) nukeAll(groupNames []*string) error {
7271
waiter := autoscaling.NewGroupNotExistsWaiter(ag.Client)
7372
err := waiter.Wait(ag.Context, &autoscaling.DescribeAutoScalingGroupsInput{
7473
AutoScalingGroupNames: deletedGroupNames,
75-
}, 5*time.Minute)
74+
}, ag.GetTimeoutWithDefault(asgDefaultWaitTimeout))
7675

7776
if err != nil {
7877
logging.Errorf("[Failed] %s", err)

aws/resources/asg_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@ package resources
22

33
import (
44
"context"
5+
"time"
56

67
"github.com/aws/aws-sdk-go-v2/aws"
78
"github.com/aws/aws-sdk-go-v2/service/autoscaling"
89
"github.com/gruntwork-io/cloud-nuke/config"
910
"github.com/gruntwork-io/go-commons/errors"
1011
)
1112

13+
const asgDefaultWaitTimeout = 5 * time.Minute
14+
1215
type ASGroupsAPI interface {
1316
DescribeAutoScalingGroups(ctx context.Context, params *autoscaling.DescribeAutoScalingGroupsInput, optFns ...func(*autoscaling.Options)) (*autoscaling.DescribeAutoScalingGroupsOutput, error)
1417
DeleteAutoScalingGroup(ctx context.Context, params *autoscaling.DeleteAutoScalingGroupInput, optFns ...func(*autoscaling.Options)) (*autoscaling.DeleteAutoScalingGroupOutput, error)

aws/resources/backup_vault.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ func (bv *BackupVault) nukeRecoveryPoints(name *string) error {
9797
}
9898

9999
func (bv *BackupVault) WaitUntilRecoveryPointsDeleted(name *string) error {
100-
timeoutCtx, cancel := context.WithTimeout(bv.Context, 1*time.Minute)
100+
waitTimeout := bv.GetTimeoutWithDefault(backupVaultDefaultWaitTimeout)
101+
timeoutCtx, cancel := context.WithTimeout(bv.Context, waitTimeout)
101102
defer cancel()
102103

103104
ticker := time.NewTicker(1 * time.Second)
@@ -106,7 +107,7 @@ func (bv *BackupVault) WaitUntilRecoveryPointsDeleted(name *string) error {
106107
for {
107108
select {
108109
case <-timeoutCtx.Done():
109-
return fmt.Errorf("recovery point deletion check timed out after 1 minute")
110+
return fmt.Errorf("recovery point deletion check timed out after %v", waitTimeout)
110111
case <-ticker.C:
111112
output, err := bv.Client.ListRecoveryPointsByBackupVault(bv.Context, &backup.ListRecoveryPointsByBackupVaultInput{
112113
BackupVaultName: name,

aws/resources/backup_vault_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@ package resources
22

33
import (
44
"context"
5+
"time"
56

67
"github.com/aws/aws-sdk-go-v2/aws"
78
"github.com/aws/aws-sdk-go-v2/service/backup"
89
"github.com/gruntwork-io/cloud-nuke/config"
910
"github.com/gruntwork-io/go-commons/errors"
1011
)
1112

13+
const backupVaultDefaultWaitTimeout = 1 * time.Minute
14+
1215
type BackupVaultAPI interface {
1316
DeleteBackupVault(ctx context.Context, params *backup.DeleteBackupVaultInput, optFns ...func(*backup.Options)) (*backup.DeleteBackupVaultOutput, error)
1417
DeleteRecoveryPoint(ctx context.Context, params *backup.DeleteRecoveryPointInput, optFns ...func(*backup.Options)) (*backup.DeleteRecoveryPointOutput, error)

aws/resources/base_resource.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,11 @@ func (br *BaseAwsResource) IsNukable(identifier string) (bool, error) {
108108

109109
return true, nil
110110
}
111+
112+
// GetTimeoutWithDefault returns the configured timeout or the provided default if not set
113+
func (br *BaseAwsResource) GetTimeoutWithDefault(defaultTimeout time.Duration) time.Duration {
114+
if br.Timeout == 0 {
115+
return defaultTimeout
116+
}
117+
return br.Timeout
118+
}

aws/resources/ebs.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package resources
33
import (
44
"context"
55
goerr "errors"
6-
"time"
76

87
"github.com/aws/aws-sdk-go-v2/aws"
98
"github.com/aws/aws-sdk-go-v2/service/ec2"
@@ -118,7 +117,7 @@ func (ev *EBSVolumes) nukeAll(volumeIds []*string) error {
118117
waiter := ec2.NewVolumeDeletedWaiter(ev.Client)
119118
err := waiter.Wait(ev.Context, &ec2.DescribeVolumesInput{
120119
VolumeIds: aws.ToStringSlice(deletedVolumeIDs),
121-
}, 5*time.Minute)
120+
}, ev.GetTimeoutWithDefault(ebsDefaultWaitTimeout))
122121
if err != nil {
123122
logging.Debugf("[Failed] %s", err)
124123
return errors.WithStackTrace(err)

aws/resources/ebs_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@ package resources
22

33
import (
44
"context"
5+
"time"
56

67
"github.com/aws/aws-sdk-go-v2/aws"
78
"github.com/aws/aws-sdk-go-v2/service/ec2"
89
"github.com/gruntwork-io/cloud-nuke/config"
910
"github.com/gruntwork-io/go-commons/errors"
1011
)
1112

13+
const ebsDefaultWaitTimeout = 5 * time.Minute
14+
1215
type EBSVolumesAPI interface {
1316
DescribeVolumes(ctx context.Context, params *ec2.DescribeVolumesInput, optFns ...func(*ec2.Options)) (*ec2.DescribeVolumesOutput, error)
1417
DeleteVolume(ctx context.Context, params *ec2.DeleteVolumeInput, optFns ...func(*ec2.Options)) (*ec2.DeleteVolumeOutput, error)

aws/resources/ec2.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package resources
22

33
import (
44
"context"
5-
"time"
65

76
"github.com/aws/aws-sdk-go-v2/aws"
87
"github.com/aws/aws-sdk-go-v2/service/ec2"
@@ -161,7 +160,7 @@ func (ei *EC2Instances) nukeAll(instanceIds []*string) error {
161160
Values: aws.ToStringSlice(instanceIds),
162161
},
163162
},
164-
}, 15*time.Minute)
163+
}, ei.GetTimeoutWithDefault(ec2DefaultWaitTimeout))
165164

166165
if err != nil {
167166
logging.Debugf("[Failed] %s", err)

aws/resources/ec2_network_interface.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ func (ni *NetworkInterface) nukeInstance(id *string) error {
212212
waiter := ec2.NewInstanceTerminatedWaiter(ni.Client)
213213
err = waiter.Wait(ni.Context, &ec2.DescribeInstancesInput{
214214
InstanceIds: []string{instanceID},
215-
}, 5*time.Minute)
215+
}, ni.GetTimeoutWithDefault(ec2NetworkInterfaceDefaultWaitTimeout))
216216
if err != nil {
217217
logging.Debugf("[nukeInstance] Instance termination waiting failed for instance %s: %v", instanceID, err)
218218
return errors.WithStackTrace(err)

aws/resources/ec2_network_interface_types.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package resources
22

33
import (
44
"context"
5+
"time"
56

67
"github.com/aws/aws-sdk-go-v2/aws"
78
"github.com/aws/aws-sdk-go-v2/service/ec2"
@@ -10,7 +11,8 @@ import (
1011
)
1112

1213
const (
13-
NetworkInterfaceTypeInterface = "interface"
14+
NetworkInterfaceTypeInterface = "interface"
15+
ec2NetworkInterfaceDefaultWaitTimeout = 5 * time.Minute
1416
)
1517

1618
type NetworkInterfaceAPI interface {

0 commit comments

Comments
 (0)