diff --git a/moto/iam/responses.py b/moto/iam/responses.py index 55a7c2076..d6f8ae020 100644 --- a/moto/iam/responses.py +++ b/moto/iam/responses.py @@ -1684,6 +1684,16 @@ USER_TEMPLATE = """<{{ action }}UserResponse> {{ user.id }} {{ user.created_iso_8601 }} {{ user.arn }} + {% if user.tags %} + + {% for tag in user.tags %} + + {{ tag['Key'] }} + {{ tag['Value'] }} + + {% endfor %} + + {% endif %} diff --git a/tests/test_iam/test_iam.py b/tests/test_iam/test_iam.py index bd9a8ab82..dd5a6991f 100644 --- a/tests/test_iam/test_iam.py +++ b/tests/test_iam/test_iam.py @@ -4002,3 +4002,20 @@ def test_list_roles_none_found_returns_empty_list(): response = iam.list_roles(MaxItems=10) roles = response["Roles"] assert len(roles) == 0 + + +@mock_iam() +def test_create_user_with_tags(): + conn = boto3.client("iam", region_name="us-east-1") + user_name = "test-user" + tags = [ + {"Key": "somekey", "Value": "somevalue"}, + {"Key": "someotherkey", "Value": "someothervalue"}, + ] + resp = conn.create_user(UserName=user_name, Tags=tags) + assert resp["User"]["Tags"] == tags + resp = conn.list_user_tags(UserName=user_name) + assert resp["Tags"] == tags + + resp = conn.create_user(UserName="test-create-user-no-tags") + assert "Tags" not in resp["User"]