From 58fd4aeaaed08cb254c630bd9f9eabf7efebd47f Mon Sep 17 00:00:00 2001 From: usmangani1 Date: Sat, 15 May 2021 00:35:40 +0530 Subject: [PATCH] Fix tags for resource in ListTagsForResource (#3931) * Fix tags for resource in ListTagsForResource * Fix review comments * Fix tests --- moto/ssm/models.py | 5 +++++ tests/test_ssm/test_ssm_boto3.py | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/moto/ssm/models.py b/moto/ssm/models.py index 5d378c499..72e9b21e3 100644 --- a/moto/ssm/models.py +++ b/moto/ssm/models.py @@ -1331,6 +1331,11 @@ class SimpleSystemManagerBackend(BaseBackend): tags or [], ) ) + + if tags: + tags = {t["Key"]: t["Value"] for t in tags} + self.add_tags_to_resource(name, "Parameter", tags) + return version def add_tags_to_resource(self, resource_type, resource_id, tags): diff --git a/tests/test_ssm/test_ssm_boto3.py b/tests/test_ssm/test_ssm_boto3.py index 2b3a7c731..18b48456f 100644 --- a/tests/test_ssm/test_ssm_boto3.py +++ b/tests/test_ssm/test_ssm_boto3.py @@ -1000,6 +1000,24 @@ def test_describe_parameters_tags(): parameters[0]["Name"].should.equal("/spam/eggs") +@mock_ssm +def test_tags_in_list_tags_from_resource(): + client = boto3.client("ssm", region_name="us-east-1") + + client.put_parameter( + Name="/spam/eggs", + Value="eggs", + Type="String", + Tags=[{"Key": "spam", "Value": "eggs"}], + ) + + tags = client.list_tags_for_resource( + ResourceId="/spam/eggs", ResourceType="Parameter" + ) + + assert tags.get("TagList") == [{"Key": "spam", "Value": "eggs"}] + + @mock_ssm def test_get_parameter_invalid(): client = client = boto3.client("ssm", region_name="us-east-1")