Repository: getmoto/moto

Issue:
RDS ReadReplicaDBInstanceIdentifiers and SourceDBInstanceIdentifier show db-name for cross-region replication
Currently in all cases, moto will use a database's name for the `ReadReplicaDBInstanceIdentifiers` and  `SourceDBInstanceIdentifier` fields in the RDSBackend. 

This aligns with AWS's states for same-region replication. However for cross-region replication, AWS provides full arns for `ReadReplicaDBInstanceIdentifiers` and `SourceDBInstanceIdentifier`. Moto does not reflect this behavior for cross-region replication. 

Can we update this for cross-region support to ensure moto stores/uses the full arn for its `DBInstanceIdentifiers`?

Reproducible steps:
1. Create a same-region replication (primary and replica in the same region) in AWS, and run a describe call on both the primary and replica. Notice both `SourceDBInstanceIdentifier` and `ReadReplicaDBInstanceIdentifiers` align with just the database name
2. Create a cross-region replication (primary in one region, replica in a second region) in AWS, and run a describe call on both the primary and replica. Notice both `SourceDBInstanceIdentifier` and `ReadReplicaDBInstanceIdentifiers` align with just the resource's full arn.
3. Create a cross-region replication using moto, and run a describe call on both the primary and replica. Notice both `SourceDBInstanceIdentifier` and `ReadReplicaDBInstanceIdentifiers` come back as the database name. (This does not align with AWS's behavior)


Discussion:
Thanks for raising this @Tmilly, and welcome to Moto - marking this as a bug.

PR's are always welcome, if you'd like to tackle this!

Resolving patch:
diff --git a/moto/rds/models.py b/moto/rds/models.py
--- a/moto/rds/models.py
+++ b/moto/rds/models.py
@@ -644,7 +644,11 @@ def address(self):
         )
 
     def add_replica(self, replica):
-        self.replicas.append(replica.db_instance_identifier)
+        if self.region_name != replica.region_name:
+            # Cross Region replica
+            self.replicas.append(replica.db_instance_arn)
+        else:
+            self.replicas.append(replica.db_instance_identifier)
 
     def remove_replica(self, replica):
         self.replicas.remove(replica.db_instance_identifier)
@@ -772,7 +776,7 @@ def create_from_cloudformation_json(
         if source_db_identifier:
             # Replica
             db_kwargs["source_db_identifier"] = source_db_identifier
-            database = rds_backend.create_database_replica(db_kwargs)
+            database = rds_backend.create_db_instance_read_replica(db_kwargs)
         else:
             database = rds_backend.create_db_instance(db_kwargs)
         return database
@@ -1360,7 +1364,7 @@ def delete_db_snapshot(self, db_snapshot_identifier):
 
         return self.database_snapshots.pop(db_snapshot_identifier)
 
-    def create_database_replica(self, db_kwargs):
+    def create_db_instance_read_replica(self, db_kwargs):
         database_id = db_kwargs["db_instance_identifier"]
         source_database_id = db_kwargs["source_db_identifier"]
         primary = self.find_db_from_id(source_database_id)
@@ -1370,6 +1374,7 @@ def create_database_replica(self, db_kwargs):
         # Shouldn't really copy here as the instance is duplicated. RDS replicas have different instances.
         replica = copy.copy(primary)
         replica.update(db_kwargs)
+        replica.region_name = self.region_name
         replica.set_as_replica()
         self.databases[database_id] = replica
         primary.add_replica(replica)
diff --git a/moto/rds/responses.py b/moto/rds/responses.py
--- a/moto/rds/responses.py
+++ b/moto/rds/responses.py
@@ -176,7 +176,7 @@ def create_db_instance(self):
     def create_db_instance_read_replica(self):
         db_kwargs = self._get_db_replica_kwargs()
 
-        database = self.backend.create_database_replica(db_kwargs)
+        database = self.backend.create_db_instance_read_replica(db_kwargs)
         template = self.response_template(CREATE_DATABASE_REPLICA_TEMPLATE)
         return template.render(database=database)
 


Test patch:
diff --git a/tests/test_rds/test_rds.py b/tests/test_rds/test_rds.py
--- a/tests/test_rds/test_rds.py
+++ b/tests/test_rds/test_rds.py
@@ -1713,6 +1713,10 @@ def test_create_database_replica():
     master["DBInstances"][0]["ReadReplicaDBInstanceIdentifiers"].should.equal(
         ["db-replica-1"]
     )
+    replica = conn.describe_db_instances(DBInstanceIdentifier="db-replica-1")[
+        "DBInstances"
+    ][0]
+    replica["ReadReplicaSourceDBInstanceIdentifier"].should.equal("db-master-1")
 
     conn.delete_db_instance(DBInstanceIdentifier="db-replica-1", SkipFinalSnapshot=True)
 
@@ -1720,6 +1724,39 @@ def test_create_database_replica():
     master["DBInstances"][0]["ReadReplicaDBInstanceIdentifiers"].should.equal([])
 
 
+@mock_rds
+def test_create_database_replica_cross_region():
+    us1 = boto3.client("rds", region_name="us-east-1")
+    us2 = boto3.client("rds", region_name="us-west-2")
+
+    source_id = "db-master-1"
+    source_arn = us1.create_db_instance(
+        DBInstanceIdentifier=source_id,
+        AllocatedStorage=10,
+        Engine="postgres",
+        DBInstanceClass="db.m1.small",
+    )["DBInstance"]["DBInstanceArn"]
+
+    target_id = "db-replica-1"
+    target_arn = us2.create_db_instance_read_replica(
+        DBInstanceIdentifier=target_id,
+        SourceDBInstanceIdentifier=source_arn,
+        DBInstanceClass="db.m1.small",
+    )["DBInstance"]["DBInstanceArn"]
+
+    source_db = us1.describe_db_instances(DBInstanceIdentifier=source_id)[
+        "DBInstances"
+    ][0]
+    source_db.should.have.key("ReadReplicaDBInstanceIdentifiers").equals([target_arn])
+
+    target_db = us2.describe_db_instances(DBInstanceIdentifier=target_id)[
+        "DBInstances"
+    ][0]
+    target_db.should.have.key("ReadReplicaSourceDBInstanceIdentifier").equals(
+        source_arn
+    )
+
+
 @mock_rds
 @mock_kms
 def test_create_database_with_encrypted_storage():