From 4b33e6531111c8bb3422662b55879a8ce9849d70 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Sat, 17 Aug 2024 16:32:51 +0000 Subject: [PATCH] fix: make sure that ec2 is cleaned up in all cases of flow end --- .github/workflows/ami-release-nix.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/ami-release-nix.yml b/.github/workflows/ami-release-nix.yml index d500af738..3b5430dd1 100644 --- a/.github/workflows/ami-release-nix.yml +++ b/.github/workflows/ami-release-nix.yml @@ -129,6 +129,11 @@ jobs: SLACK_MESSAGE: 'Building Postgres AMI failed' SLACK_FOOTER: '' + - name: Cleanup resources on build cancellation + if: ${{ always() }} + run: | + aws ec2 describe-instances --filters "Name=tag:packerExecutionId,Values=${GITHUB_RUN_ID}" --query "Reservations[].Instances[].InstanceId" --output text | xargs -n 1 -I {} aws ec2 terminate-instances --instance-ids {} + - name: Cleanup resources on build cancellation if: ${{ cancelled() }} run: |