osbuild-service-maintenance/aws: avoid error on empty list

Passing an empty list to `TerminateInstances` causes an
error message, which is not necessary, as there is
nothing to terminate.
This commit is contained in:
Florian Schüller 2024-12-04 16:23:56 +01:00 committed by Florian Schüller
parent 24e256c225
commit 87ef1527fc

View file

@ -158,9 +158,11 @@ func terminateOrphanedSecureInstances(a *awscloud.AWS, dryRun bool) error {
instanceIDs = filterOnTooOld(instanceIDs, reservations)
logrus.Infof("Cleaning up executor instances: %v", instanceIDs)
if !dryRun {
err = a.TerminateInstances(instanceIDs)
if err != nil {
return fmt.Errorf("Unable to terminate secure instances: %w", err)
if len(instanceIDs) > 0 {
err = a.TerminateInstances(instanceIDs)
if err != nil {
return fmt.Errorf("Unable to terminate secure instances: %w", err)
}
}
} else {
logrus.Info("Dry run, didn't actually terminate any instances")