Skip to content

Commit

Permalink
Retry security group deletion for dependency cycles
Browse files Browse the repository at this point in the history
  • Loading branch information
acdha committed Oct 14, 2020
1 parent 5842c59 commit 0a655ca
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions remove_vpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,18 @@ def delete_sgps(ec2, args):

sgps = ec2.describe_security_groups(**args)["SecurityGroups"]

if sgps:
for sgp in sgps:
default = sgp["GroupName"]
if default == "default":
continue
sg_id = sgp["GroupId"]
ec2.delete_security_group(GroupId=sg_id)
non_default_sg_ids = [i["GroupId"] for i in sgps if i["GroupName"] != "default"]
tries = 0
max_tries = len(sgps)

while len(non_default_sg_ids) > 1 and tries < max_tries:
for sg_id in non_default_sg_ids:
try:
ec2.delete_security_group(GroupId=sg_id)
except ClientError as exc:
print(exc, file=sys.stderr)

tries += 1


def delete_vpc(ec2, vpc_id, region):
Expand Down

0 comments on commit 0a655ca

Please sign in to comment.