Skip to content

Commit

Permalink
fixing cloudformation.create_or_update when ShouldDeleteRollbackCompl…
Browse files Browse the repository at this point in the history
…ete == True
  • Loading branch information
eamonnfaherty committed Aug 31, 2021
1 parent 486d372 commit 43bcee7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
18 changes: 10 additions & 8 deletions betterboto/cloudformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 43bcee7

Please sign in to comment.