Work-around for empty changesets with status FAILED being created (#34933)

* Added check to prevent failed empty changesets from being left behind

* Fixing comments from PR 34933, prevent infinte loop and stricter exception catching
This commit is contained in:
RobReus 2018-01-17 17:00:28 +01:00 committed by Ryan Brown
parent 9d4d86237d
commit 53266e31df

View file

@ -346,6 +346,25 @@ def create_changeset(module, stack_params, cfn):
result = dict(changed=False, output='ChangeSet %s already exists.' % changeset_name, warnings=[warning])
else:
cs = cfn.create_change_set(**stack_params)
# Make sure we don't enter an infinite loop
time_end = time.time() + 600
while time.time() < time_end:
try:
newcs = cfn.describe_change_set(ChangeSetName=cs['Id'])
except botocore.exceptions.BotoCoreError as err:
error_msg = boto_exception(err)
module.fail_json(msg=error_msg)
if newcs['Status'] == 'CREATE_PENDING' or newcs['Status'] == 'CREATE_IN_PROGRESS':
time.sleep(1)
elif newcs['Status'] == 'FAILED' and "The submitted information didn't contain changes" in newcs['StatusReason']:
cfn.delete_change_set(ChangeSetName=cs['Id'])
result = dict(changed=False,
output='Stack is already up-to-date, Change Set refused to create due to lack of changes.')
module.exit_json(**result)
else:
break
# Lets not hog the cpu/spam the AWS API
time.sleep(1)
result = stack_operation(cfn, stack_params['StackName'], 'CREATE_CHANGESET')
result['warnings'] = ['Created changeset named %s for stack %s' % (changeset_name, stack_params['StackName']),
'You can execute it using: aws cloudformation execute-change-set --change-set-name %s' % cs['Id'],