diff --git a/moto/organizations/models.py b/moto/organizations/models.py index 80362a3d6..aa3ffb3fd 100644 --- a/moto/organizations/models.py +++ b/moto/organizations/models.py @@ -200,6 +200,7 @@ class FakePolicy(BaseModel): self.organization_id = organization.id self.master_account_id = organization.master_account_id self.attachments: List[Any] = [] + self.tags = {tag["Key"]: tag["Value"] for tag in kwargs.get("Tags", [])} if not FakePolicy.supported_policy_type(self.type): raise InvalidInputException("You specified an invalid value.") diff --git a/tests/test_organizations/test_organizations_boto3.py b/tests/test_organizations/test_organizations_boto3.py index 5e7e8f85f..7f83dbc2d 100644 --- a/tests/test_organizations/test_organizations_boto3.py +++ b/tests/test_organizations/test_organizations_boto3.py @@ -1244,6 +1244,38 @@ def test_tag_resource_organization_organizational_unit(): response["Tags"].should.equal([]) +@mock_organizations +def test_tag_resource_policy(): + client = boto3.client("organizations", region_name="us-east-1") + client.create_organization(FeatureSet="ALL") + _ = client.list_roots()["Roots"][0]["Id"] + + resource_id = client.create_policy( + Content=json.dumps(policy_doc01), + Description="A dummy service control policy", + Name="MockServiceControlPolicy", + Type="SERVICE_CONTROL_POLICY", + )["Policy"]["PolicySummary"]["Id"] + + client.tag_resource(ResourceId=resource_id, Tags=[{"Key": "key", "Value": "value"}]) + + response = client.list_tags_for_resource(ResourceId=resource_id) + response["Tags"].should.equal([{"Key": "key", "Value": "value"}]) + + # adding a tag with an existing key, will update the value + client.tag_resource( + ResourceId=resource_id, Tags=[{"Key": "key", "Value": "new-value"}] + ) + + response = client.list_tags_for_resource(ResourceId=resource_id) + response["Tags"].should.equal([{"Key": "key", "Value": "new-value"}]) + + client.untag_resource(ResourceId=resource_id, TagKeys=["key"]) + + response = client.list_tags_for_resource(ResourceId=resource_id) + response["Tags"].should.equal([]) + + @mock_organizations def test_tag_resource_errors(): client = boto3.client("organizations", region_name="us-east-1")