Repository: getmoto/moto
Pull request #7093 (2023-12-04 21:02:06)

ResourceGroupsTaggingAPI: add sqs tags
Adding SQS Tagging functionality to resourcetaggingapi


Patch:
diff --git a/moto/resourcegroupstaggingapi/models.py b/moto/resourcegroupstaggingapi/models.py
index 5e904b9c6..41219e4d5 100644
--- a/moto/resourcegroupstaggingapi/models.py
+++ b/moto/resourcegroupstaggingapi/models.py
@@ -18,6 +18,7 @@ from moto.moto_api._internal import mock_random
 from moto.rds.models import RDSBackend, rds_backends
 from moto.redshift.models import RedshiftBackend, redshift_backends
 from moto.s3.models import S3Backend, s3_backends
+from moto.sqs.models import SQSBackend, sqs_backends
 from moto.utilities.tagging_service import TaggingService
 
 # Left: EC2 ElastiCache RDS ELB CloudFront WorkSpaces Lambda EMR Glacier Kinesis Redshift Route53
@@ -95,6 +96,10 @@ class ResourceGroupsTaggingAPIBackend(BaseBackend):
     def acm_backend(self) -> AWSCertificateManagerBackend:
         return acm_backends[self.account_id][self.region_name]
 
+    @property
+    def sqs_backend(self) -> SQSBackend:
+        return sqs_backends[self.account_id][self.region_name]
+
     def _get_resources_generator(
         self,
         tag_filters: Optional[List[Dict[str, Any]]] = None,
@@ -442,6 +447,17 @@ class ResourceGroupsTaggingAPIBackend(BaseBackend):
         # RedShift Snapshot
         # RedShift Subnet group
 
+        # SQS
+        if not resource_type_filters or "sqs" in resource_type_filters:
+            for queue in self.sqs_backend.queues.values():
+                tags = format_tags(queue.tags)
+                if not tags or not tag_filter(
+                    tags
+                ):  # Skip if no tags, or invalid filter
+                    continue
+
+                yield {"ResourceARN": f"{queue.queue_arn}", "Tags": tags}
+
         # VPC
         if (
             not resource_type_filters


Test patch:
diff --git a/.github/workflows/tests_sdk_dotnet.yml b/.github/workflows/tests_sdk_dotnet.yml
index cf84b9f7e..2c10a8a1b 100644
--- a/.github/workflows/tests_sdk_dotnet.yml
+++ b/.github/workflows/tests_sdk_dotnet.yml
@@ -19,7 +19,7 @@ jobs:
         python -m build
         docker run --rm -t --name motoserver -e TEST_SERVER_MODE=true -e AWS_SECRET_ACCESS_KEY=server_secret -e AWS_ACCESS_KEY_ID=server_key -v `pwd`:/moto -p 5000:5000 -v /var/run/docker.sock:/var/run/docker.sock python:3.10-slim /moto/scripts/ci_moto_server.sh &
         python scripts/ci_wait_for_server.py
-    - uses: actions/setup-dotnet@v3
+    - uses: actions/setup-dotnet@v4
     - uses: actions/cache@v3
       with:
         path: ~/.nuget/packages
diff --git a/.github/workflows/tests_sdk_java.yml b/.github/workflows/tests_sdk_java.yml
index 6e8199648..b2b8a523f 100644
--- a/.github/workflows/tests_sdk_java.yml
+++ b/.github/workflows/tests_sdk_java.yml
@@ -19,7 +19,7 @@ jobs:
         python -m build
         docker run --rm -t --name motoserver -e TEST_SERVER_MODE=true -e AWS_SECRET_ACCESS_KEY=server_secret -e AWS_ACCESS_KEY_ID=server_key -v `pwd`:/moto -p 5000:5000 -v /var/run/docker.sock:/var/run/docker.sock python:3.10-slim /moto/scripts/ci_moto_server.sh &
         python scripts/ci_wait_for_server.py
-    - uses: actions/setup-java@v3
+    - uses: actions/setup-java@v4
       with:
         distribution: 'temurin'
         java-version: '17'
diff --git a/tests/test_resourcegroupstaggingapi/test_resourcegroupstaggingapi.py b/tests/test_resourcegroupstaggingapi/test_resourcegroupstaggingapi.py
index 980c6b9d3..88fc908c1 100644
--- a/tests/test_resourcegroupstaggingapi/test_resourcegroupstaggingapi.py
+++ b/tests/test_resourcegroupstaggingapi/test_resourcegroupstaggingapi.py
@@ -14,6 +14,7 @@ from moto import (
     mock_lambda,
     mock_resourcegroupstaggingapi,
     mock_s3,
+    mock_sqs,
 )
 from tests import EXAMPLE_AMI_ID, EXAMPLE_AMI_ID2
 
@@ -715,6 +716,37 @@ def test_get_resources_lambda():
     assert_response(resp, [rectangle_arn])
 
 
+@mock_sqs
+@mock_resourcegroupstaggingapi
+def test_get_resources_sqs():
+    sqs = boto3.resource("sqs", region_name="eu-central-1")
+
+    # Create two tagged SQS queues
+    for i in range(1, 3):
+        i_str = str(i)
+
+        sqs.create_queue(
+            QueueName="sqs-tag-value-" + i_str,
+            tags={
+                "Test": i_str,
+            },
+        )
+
+    rtapi = boto3.client("resourcegroupstaggingapi", region_name="eu-central-1")
+
+    # Basic test
+    resp = rtapi.get_resources(ResourceTypeFilters=["sqs"])
+    assert len(resp["ResourceTagMappingList"]) == 2
+
+    # Test tag filtering
+    resp = rtapi.get_resources(
+        ResourceTypeFilters=["sqs"],
+        TagFilters=[{"Key": "Test", "Values": ["1"]}],
+    )
+    assert len(resp["ResourceTagMappingList"]) == 1
+    assert {"Key": "Test", "Value": "1"} in resp["ResourceTagMappingList"][0]["Tags"]
+
+
 @mock_resourcegroupstaggingapi
 def test_tag_resources_for_unknown_service():
     rtapi = boto3.client("resourcegroupstaggingapi", region_name="us-west-2")