From 43bcee7e111b9f9cac26cc5621bf1ad936b66170 Mon Sep 17 00:00:00 2001 From: Eamonn Faherty Date: Tue, 31 Aug 2021 13:05:39 +0100 Subject: [PATCH] fixing cloudformation.create_or_update when ShouldDeleteRollbackComplete == True --- betterboto/cloudformation.py | 18 ++++++++++-------- setup.py | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/betterboto/cloudformation.py b/betterboto/cloudformation.py index 8d387b4..9eacd2d 100644 --- a/betterboto/cloudformation.py +++ b/betterboto/cloudformation.py @@ -32,20 +32,22 @@ def create_or_update(self, ShouldUseChangeSets=True, ShouldDeleteRollbackComplet is_first_run = True try: - describe_stack = self.describe_stacks( + described_stacks = self.describe_stacks( StackName=stack_name ) - if ShouldDeleteRollbackComplete: - if len(describe_stack.get('Stacks', []) > 0) and describe_stack.get('Stacks')[0].get("StackStatus", "") == "ROLLBACK_COMPLETE": - logger.info("Stack with id {} is ROLLBACK_COMPLETE, deleting".format(stack_name)) - ensure_deleted(self, stack_name) - is_first_run = True - else: - is_first_run = False + is_first_run = False except self.exceptions.ClientError as e: if "Stack with id {} does not exist".format(stack_name) not in str(e): raise e + if ShouldDeleteRollbackComplete and not is_first_run: + for stack in described_stacks.get('Stacks', []): + if stack.get("StackStatus") == "ROLLBACK_COMPLETE": + reason = stack.get('StackStatusReason', 'Unknown') + logger.info(f"Stack with id {stack_name} is ROLLBACK_COMPLETE because {reason}, deleting") + ensure_deleted(self, stack_name) + is_first_run = True + if is_first_run: logger.info('Creating: {}'.format(stack_name)) self.create_stack(**kwargs) diff --git a/setup.py b/setup.py index 2c7e372..addabc7 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ setuptools.setup( name="better-boto", - version="0.41.2", + version="0.42.0", author="Eamonn Faherty", author_email="python-packages@designandsolve.co.uk", description="Helpers to make using boto3 more enjoyable",