Skip to content

Commit

Permalink
Make iam module more predictable and idempotent … (ansible-collection…
Browse files Browse the repository at this point in the history
…s#369)

* Make iam module more predictable and idempotent on returning the user_name it creates/deletes
* Add changelog fragment for iam module change
  • Loading branch information
stefanhorning authored Mar 24, 2021
1 parent b366e94 commit d8e11ba
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/369-iam-return-values.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- iam - Make iam module more predictable when returning the ``user_name`` it creates or deletes (https://github.com/ansible-collections/community.aws/pull/369).
6 changes: 3 additions & 3 deletions plugins/modules/iam.py
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ def main():
(user_groups, changed) = set_users_groups(
module, iam, name, groups, been_updated, new_name)
module.exit_json(
user_meta=meta, groups=user_groups, keys=keys, changed=changed)
user_meta=meta, groups=user_groups, user_name=meta['created_user']['user_name'], keys=keys, changed=changed)

elif state in ['present', 'update'] and user_exists:
if update_pw == 'on_create':
Expand Down Expand Up @@ -778,7 +778,7 @@ def main():
created_keys=new_key, user_meta=user_meta)
elif new_name and not new_path and not been_updated:
module.exit_json(
changed=changed, groups=user_groups, old_user_name=orig_name, new_user_name=new_name, keys=key_list,
changed=changed, groups=user_groups, old_user_name=orig_name, user_name=new_name, new_user_name=new_name, keys=key_list,
created_keys=new_key, user_meta=user_meta)
elif new_name and not new_path and been_updated:
module.exit_json(
Expand All @@ -802,7 +802,7 @@ def main():
try:
set_users_groups(module, iam, name, '')
name, changed = delete_user(module, iam, name)
module.exit_json(deleted_user=name, changed=changed)
module.exit_json(deleted_user=name, user_name=name, changed=changed)

except Exception as ex:
module.fail_json(changed=changed, msg=str(ex))
Expand Down

0 comments on commit d8e11ba

Please sign in to comment.