getmoto / moto

A library that allows you to easily mock out tests based on AWS infrastructure.

Home Page:http://docs.getmoto.org/en/latest/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

IAM - create_policy returns bad tags

thomas-desforges opened this issue · comments

Hi, Thank you for this great library!

I just noticed a small bug in IAM implementation. Using latest moto version with python mocks.
The function create_policy returns the policy tags with this format:
[{"tag_key": {"tag_key": "tag_value"}},...] instead of [{"tag_key": "tag_value"}]

I took a quick look at the code and seems like the function policy.get_tag() that does the conversion is never called and instead the response template use the tags attribute from the Policy class which is in the wrong format.

So an easy fix would be to do like get_policy response template and use get_tags() (in create_policy response template). Replacing:

{% for tag_key, tag_value in policy.tags.items() %}

by

{% for tag_key, tag_value in policy.get_tags().items() %}

There might be more like this in IAM looking at the templates but I did not dig further.

Hi @thomas-desforges, thank you for raising this! I've opened a PR with a fix.