diff --git a/changelogs/fragments/507-fix_cloudformation_changeset_detection.yml b/changelogs/fragments/507-fix_cloudformation_changeset_detection.yml new file mode 100644 index 00000000000..b9c819b0e13 --- /dev/null +++ b/changelogs/fragments/507-fix_cloudformation_changeset_detection.yml @@ -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). diff --git a/plugins/modules/cloudformation.py b/plugins/modules/cloudformation.py index 998a6ca4296..f5266b3ae53 100644 --- a/plugins/modules/cloudformation.py +++ b/plugins/modules/cloudformation.py @@ -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.') @@ -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: