diff --git a/.github/workflows/resource-cleanup.yml b/.github/workflows/resource-cleanup.yml index 22fa62ea6..d335c8931 100644 --- a/.github/workflows/resource-cleanup.yml +++ b/.github/workflows/resource-cleanup.yml @@ -45,7 +45,7 @@ jobs: role-to-assume: arn:aws:iam::${{ env.ACCOUNT_ID }}:role/${{ secrets.RESOURCE_CLEANER_ROLE_NAME }} aws-region: ${{ matrix.aws-region }} - - name: Cleanup EC2 instances + - name: Cleanup EC2 instances and ASGs working-directory: .github/workflows/util/clean/ec2_instance_cleanup env: AWS_DEFAULT_REGION: ${{ matrix.aws-region }} diff --git a/.github/workflows/util/clean/ec2_instance_cleanup/cleaner.py b/.github/workflows/util/clean/ec2_instance_cleanup/cleaner.py index 4d904eb0b..aa52a3cf6 100644 --- a/.github/workflows/util/clean/ec2_instance_cleanup/cleaner.py +++ b/.github/workflows/util/clean/ec2_instance_cleanup/cleaner.py @@ -66,7 +66,7 @@ def _delete_autoscaling_groups(auto_scaling_groups): logging.info("===== Response for delete autoscaling group request =====") logging.info(response) except Exception as e: - logging.info(f"Error terminating instances: {e}") + logging.info(f"Error deleting groups: {e}") def _is_active(asg): for instance in asg['Instances']: @@ -191,13 +191,18 @@ def _terminate_instances(instances_to_terminate): instances = _get_instances_to_terminate() if len(groups) == 0 and len(instances) == 0: - logging.info("No resource to terminate") + logging.info("No resource to clean up") exit(0) report_successful = _prepare_report_and_upload(groups, instances) if not report_successful: - logging.error("Failed to prepare report and upload. Aborting termination of instances.") + logging.error("Failed to prepare report and upload. Aborting resource clean up.") exit(1) - _delete_autoscaling_groups(groups) - _terminate_instances(instances) + if len(groups) > 0: + logging.info("Deleting autoscaling groups...") + _delete_autoscaling_groups(groups) + + if len(instances) > 0: + logging.info("Terminating instances...") + _terminate_instances(instances)