Repository: getmoto/moto

Issue:
SQS PhysicalResourceId should always be its QueueUrl
According to the [AWS CFN docs for SQS](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-sqs-queues.html#aws-properties-sqs-queues-return-values-ref), the physical resource ID should be its queue URL.

>Ref
>
>When you pass the logical ID of this resource to the intrinsic Ref function, Ref returns the queue URL. For example:
>
>{ "Ref": "https://sqs.us-east-2.amazonaws.com/123456789012/aa4-MyQueue-Z5NOSZO2PZE9" }

However, `moto` currently uses the queue name as the physical resource ID:

https://github.com/spulec/moto/blob/3a5d857a60c3a2d140ed2c8adfe8dcaf71a4cac8/moto/sqs/models.py#L322-L324




Discussion:
Thanks; setting this as a feature request.

Resolving patch:
diff --git a/moto/sqs/models.py b/moto/sqs/models.py
--- a/moto/sqs/models.py
+++ b/moto/sqs/models.py
@@ -37,7 +37,7 @@
     InvalidAttributeValue,
 )
 
-from moto.core import ACCOUNT_ID as DEFAULT_ACCOUNT_ID
+from moto.core import ACCOUNT_ID
 
 DEFAULT_SENDER_ID = "AIDAIT2UOQQY3AUEKVGXU"
 
@@ -262,7 +262,7 @@ def __init__(self, name, region, **kwargs):
         now = unix_time()
         self.created_timestamp = now
         self.queue_arn = "arn:aws:sqs:{0}:{1}:{2}".format(
-            self.region, DEFAULT_ACCOUNT_ID, self.name
+            self.region, ACCOUNT_ID, self.name
         )
         self.dead_letter_queue = None
 
@@ -454,8 +454,11 @@ def update_from_cloudformation_json(
     def delete_from_cloudformation_json(
         cls, resource_name, cloudformation_json, region_name
     ):
+        # ResourceName will be the full queue URL - we only need the name
+        # https://sqs.us-west-1.amazonaws.com/123456789012/queue_name
+        queue_name = resource_name.split("/")[-1]
         sqs_backend = sqs_backends[region_name]
-        sqs_backend.delete_queue(resource_name)
+        sqs_backend.delete_queue(queue_name)
 
     @property
     def approximate_number_of_messages_delayed(self):
@@ -471,7 +474,7 @@ def approximate_number_of_messages(self):
 
     @property
     def physical_resource_id(self):
-        return self.name
+        return f"https://sqs.{self.region}.amazonaws.com/{ACCOUNT_ID}/{self.name}"
 
     @property
     def attributes(self):
@@ -505,7 +508,7 @@ def attributes(self):
 
     def url(self, request_url):
         return "{0}://{1}/{2}/{3}".format(
-            request_url.scheme, request_url.netloc, DEFAULT_ACCOUNT_ID, self.name
+            request_url.scheme, request_url.netloc, ACCOUNT_ID, self.name
         )
 
     @property


Test patch:
diff --git a/tests/test_sqs/test_sqs_cloudformation.py b/tests/test_sqs/test_sqs_cloudformation.py
--- a/tests/test_sqs/test_sqs_cloudformation.py
+++ b/tests/test_sqs/test_sqs_cloudformation.py
@@ -62,7 +62,7 @@ def test_describe_stack_subresources():
     for s in stack.resource_summaries.all():
         s.resource_type.should.equal("AWS::SQS::Queue")
         s.logical_id.should.equal("QueueGroup")
-        s.physical_resource_id.should.equal(q_name)
+        s.physical_resource_id.should.contain(f"/{q_name}")
 
 
 @mock_sqs
@@ -83,7 +83,8 @@ def test_list_stack_resources():
 
     queue.should.have.key("ResourceType").equal("AWS::SQS::Queue")
     queue.should.have.key("LogicalResourceId").should.equal("QueueGroup")
-    queue.should.have.key("PhysicalResourceId").should.equal(q_name)
+    expected_url = f"https://sqs.us-east-1.amazonaws.com/{ACCOUNT_ID}/{q_name}"
+    queue.should.have.key("PhysicalResourceId").should.equal(expected_url)
 
 
 @mock_sqs
@@ -96,7 +97,7 @@ def test_create_from_cloudformation_json_with_tags():
     cf.create_stack(StackName=stack_name, TemplateBody=sqs_template_with_tags)
 
     response = cf.describe_stack_resources(StackName=stack_name)
-    q_name = response["StackResources"][0]["PhysicalResourceId"]
+    q_name = response["StackResources"][0]["PhysicalResourceId"].split("/")[-1]
 
     all_urls = client.list_queues(QueueNamePrefix=q_name)["QueueUrls"]
     queue_url = [url for url in all_urls if url.endswith(q_name)][0]