Repository: getmoto/moto
Pull request: Fix error listing tags for rds db subnet group
Suggested solution to https://github.com/spulec/moto/issues/5479

Problem statement:
When trying to create the subnet group get error: Error listing tags for RDS DB Subnet Group
**Repro steps:**

1. Start moto server.
2. Prepare terraform file that will create rds db subnet group.
3. Run terraform init; terraform apply

**Description:**
When attempting to create a subnet group terraform errors out with error: "Error listing tags for RDS DB Subnet Group: InvalidParameterValue: Invalid resource name:"

**Observed results:**
An error on attempted creation of rds db subnet group

**expected results:**
It is possible to create an rds db subnet group without issues

Hints from issue discussion:
PR with proposed solution https://github.com/spulec/moto/pull/5480

Commit message: fix tests

Patch to review:
diff --git a/moto/rds/models.py b/moto/rds/models.py
index 7ce5ef605f85..938770f962a5 100644
--- a/moto/rds/models.py
+++ b/moto/rds/models.py
@@ -1145,13 +1145,19 @@ def delete(self, account_id, region_name):
 
 
 class SubnetGroup(CloudFormationModel):
-    def __init__(self, subnet_name, description, subnets, tags):
+    def __init__(self, subnet_name, description, subnets, tags, region, account_id):
         self.subnet_name = subnet_name
         self.description = description
         self.subnets = subnets
         self.status = "Complete"
         self.tags = tags
         self.vpc_id = self.subnets[0].vpc_id
+        self.region = region
+        self.account_id = account_id
+
+    @property
+    def sg_arn(self):
+        return f"arn:aws:rds:{self.region}:{self.account_id}:subgrp:{self.subnet_name}"
 
     def to_xml(self):
         template = Template(
@@ -1160,6 +1166,7 @@ def to_xml(self):
               <SubnetGroupStatus>{{ subnet_group.status }}</SubnetGroupStatus>
               <DBSubnetGroupDescription>{{ subnet_group.description }}</DBSubnetGroupDescription>
               <DBSubnetGroupName>{{ subnet_group.subnet_name }}</DBSubnetGroupName>
+              <DBSubnetGroupArn>{{ subnet_group.sg_arn }}</DBSubnetGroupArn>
               <Subnets>
                 {% for subnet in subnet_group.subnets %}
                 <Subnet>
@@ -1222,7 +1229,7 @@ def create_from_cloudformation_json(
         subnets = [ec2_backend.get_subnet(subnet_id) for subnet_id in subnet_ids]
         rds_backend = rds_backends[account_id][region_name]
         subnet_group = rds_backend.create_subnet_group(
-            resource_name, description, subnets, tags
+            resource_name, description, subnets, tags, region_name, account_id
         )
         return subnet_group
 
@@ -1485,8 +1492,12 @@ def authorize_security_group(self, security_group_name, cidr_ip):
         security_group.authorize_cidr(cidr_ip)
         return security_group
 
-    def create_subnet_group(self, subnet_name, description, subnets, tags):
-        subnet_group = SubnetGroup(subnet_name, description, subnets, tags)
+    def create_subnet_group(
+        self, subnet_name, description, subnets, tags, region, account_id
+    ):
+        subnet_group = SubnetGroup(
+            subnet_name, description, subnets, tags, region, account_id
+        )
         self.subnet_groups[subnet_name] = subnet_group
         return subnet_group
 
diff --git a/moto/rds/responses.py b/moto/rds/responses.py
index 862f344443e4..9434a9aa9cad 100644
--- a/moto/rds/responses.py
+++ b/moto/rds/responses.py
@@ -352,7 +352,7 @@ def create_db_subnet_group(self):
             for subnet_id in subnet_ids
         ]
         subnet_group = self.backend.create_subnet_group(
-            subnet_name, description, subnets, tags
+            subnet_name, description, subnets, tags, self.region, self.current_account
         )
         template = self.response_template(CREATE_SUBNET_GROUP_TEMPLATE)
         return template.render(subnet_group=subnet_group)


Code review comments:
diff_hunk: @@ -1485,8 +1492,12 @@ def authorize_security_group(self, security_group_name, cidr_ip):
         security_group.authorize_cidr(cidr_ip)
         return security_group
 
-    def create_subnet_group(self, subnet_name, description, subnets, tags):
-        subnet_group = SubnetGroup(subnet_name, description, subnets, tags)
+    def create_subnet_group(
+        self, subnet_name, description, subnets, tags, region, account_id
path: moto/rds/models.py
text: @user1:
The region and account are already available in the backend, so we don't have to pass them explicitly.
`self.region_name` and `self.account_id` out the top of my head