added resourcegroupstaggingapi support for ssm (#7430)

This commit is contained in:
vgiridhar97 2024-03-18 15:04:52 -04:00 committed by GitHub
parent 40a86b7fb4
commit c0152f206f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 49 additions and 0 deletions

View File

@ -22,6 +22,7 @@ from moto.redshift.models import RedshiftBackend, redshift_backends
from moto.s3.models import S3Backend, s3_backends
from moto.sns.models import SNSBackend, sns_backends
from moto.sqs.models import SQSBackend, sqs_backends
from moto.ssm.models import SimpleSystemManagerBackend, ssm_backends
from moto.utilities.tagging_service import TaggingService
# Left: EC2 ElastiCache RDS ELB CloudFront WorkSpaces Lambda EMR Glacier Kinesis Redshift Route53
@ -102,6 +103,10 @@ class ResourceGroupsTaggingAPIBackend(BaseBackend):
@property
def sns_backend(self) -> SNSBackend:
return sns_backends[self.account_id][self.region_name]
@property
def ssm_backend(self) -> SimpleSystemManagerBackend:
return ssm_backends[self.account_id][self.region_name]
@property
def sqs_backend(self) -> SQSBackend:
@ -512,6 +517,22 @@ class ResourceGroupsTaggingAPIBackend(BaseBackend):
continue
yield {"ResourceARN": f"{topic.arn}", "Tags": tags}
# SSM
if not resource_type_filters or "ssm" in resource_type_filters:
for document in self.ssm_backend._documents.values():
doc_name = document.describe()["Name"]
tags = self.ssm_backend._get_documents_tags(doc_name)
if not tags or not tag_filter(
tags
): # Skip if no tags, or invalid filter
continue
yield {
"ResourceARN": f"arn:aws:ssm:{self.region_name}:{self.account_id}:document/{doc_name}",
"Tags": tags,
}
# VPC
if (
not resource_type_filters

View File

@ -759,6 +759,34 @@ def test_get_resources_sns():
"Tags"
]
@mock_aws
def test_get_resources_ssm():
import json
import yaml
from tests.test_ssm.test_ssm_docs import _get_yaml_template
template_file = _get_yaml_template()
json_doc = yaml.safe_load(template_file)
ssm = boto3.client("ssm", region_name="us-east-1")
ssm.create_document(
Content=json.dumps(json_doc),
Name="TestDocument",
DocumentType="Command",
DocumentFormat="JSON",
Tags=[{"Key": 'testing', "Value": "testingValue"}],
)
rtapi = boto3.client("resourcegroupstaggingapi", region_name="us-east-1")
resp = rtapi.get_resources(ResourceTypeFilters=["ssm"])
assert len(resp["ResourceTagMappingList"]) == 1
assert {"Key": 'testing', "Value": "testingValue"} in resp["ResourceTagMappingList"][0][
"Tags"
]
@mock_aws
def test_tag_resources_for_unknown_service():