From d8f996c60221dd70aece46e93ff8e5548e811e7f Mon Sep 17 00:00:00 2001 From: Karsten ROY Date: Tue, 10 Dec 2024 14:11:28 +0100 Subject: [PATCH] fix: handle destroy with missing security group --- flintrock/ec2.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/flintrock/ec2.py b/flintrock/ec2.py index ecd1cda..3a10849 100644 --- a/flintrock/ec2.py +++ b/flintrock/ec2.py @@ -197,13 +197,15 @@ def destroy(self): time.sleep(1) # TODO: Centralize logic to get cluster security group name from cluster name. - cluster_group = list( + cluster_group_list = list( ec2.security_groups.filter( Filters=[ {'Name': 'group-name', 'Values': ['flintrock-' + self.name]}, {'Name': 'vpc-id', 'Values': [self.vpc_id]}, - ]))[0] - cluster_group.delete() + ])) + # Cluster group might already have been killed if a destroy was ungracefully stopped during a previous execution + if len(cluster_group_list) > 0: + cluster_group_list[0].delete() (ec2.instances .filter(