Skip to content

Commit

Permalink
Fix how CloudFormation stack changes are detected (#507)
Browse files Browse the repository at this point in the history
Fix how CloudFormation stack changes are detected

Most of the times when there are no changes, the change set will have a status FAILED with StatusReason="The submitted information didn't contain changes. Submit different information to create a change set.", but sometimes StatusReason is "No updates are to be performed."

Reviewed-by: Mark Chappell <None>
Reviewed-by: None <None>
  • Loading branch information
devt authored Oct 6, 2021
1 parent b93afa8 commit ee22c8c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
minor_changes:
- cloudformation - fix detection when there are no changes.
Sometimes when there are no changes, the change set will have a status FAILED with StatusReason
No updates are to be performed
(https://github.com/ansible-collections/amazon.aws/pull/507).
7 changes: 4 additions & 3 deletions plugins/modules/cloudformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,8 @@ def create_changeset(module, stack_params, cfn, events_limit):
module.fail_json_aws(err)
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']:
elif newcs['Status'] == 'FAILED' and ("The submitted information didn't contain changes" in newcs['StatusReason']
or "No updates are to be performed" in newcs['StatusReason']):
cfn.delete_change_set(aws_retry=True, ChangeSetName=cs['Id'])
result = dict(changed=False,
output='The created Change Set did not contain any changes to this stack and was deleted.')
Expand Down Expand Up @@ -594,8 +595,8 @@ def check_mode_changeset(module, stack_params, cfn):

reason = description.get('StatusReason')

if description['Status'] == 'FAILED' and "didn't contain changes" in description['StatusReason']:
return {'changed': False, 'msg': reason, 'meta': description['StatusReason']}
if description['Status'] == 'FAILED' and ("didn't contain changes" in reason or "No updates are to be performed" in reason):
return {'changed': False, 'msg': reason, 'meta': reason}
return {'changed': True, 'msg': reason, 'meta': description['Changes']}

except (botocore.exceptions.ValidationError, botocore.exceptions.ClientError) as err:
Expand Down

0 comments on commit ee22c8c

Please sign in to comment.