Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AvailabilityZone to describe_db_instances #5373

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions moto/rds/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,8 @@ def __init__(self, **kwargs):
if self.backup_retention_period is None:
self.backup_retention_period = 1
self.availability_zone = kwargs.get("availability_zone")
if not self.availability_zone:
self.availability_zone = f"{self.region_name}a"
self.multi_az = kwargs.get("multi_az")
self.db_subnet_group_name = kwargs.get("db_subnet_group_name")
if self.db_subnet_group_name:
Expand Down Expand Up @@ -495,6 +497,7 @@ def default_db_parameter_group_details(self):
def to_xml(self):
template = Template(
"""<DBInstance>
<AvailabilityZone>{{ database.availability_zone }}</AvailabilityZone>
<BackupRetentionPeriod>{{ database.backup_retention_period }}</BackupRetentionPeriod>
<DBInstanceStatus>{{ database.status }}</DBInstanceStatus>
{% if database.db_name %}<DBName>{{ database.db_name }}</DBName>{% endif %}
Expand Down
36 changes: 36 additions & 0 deletions tests/test_rds/test_rds.py
Original file line number Diff line number Diff line change
Expand Up @@ -2019,3 +2019,39 @@ def test_create_db_instance_with_tags():

resp = client.describe_db_instances(DBInstanceIdentifier=db_instance_identifier)
resp["DBInstances"][0]["TagList"].should.equal(tags)


@mock_rds
def test_create_db_instance_without_availability_zone():
region = "us-east-1"
client = boto3.client("rds", region_name=region)
db_instance_identifier = "test-db-instance"
resp = client.create_db_instance(
DBInstanceIdentifier=db_instance_identifier,
Engine="postgres",
DBName="staging-postgres",
DBInstanceClass="db.m1.small",
)
resp["DBInstance"]["AvailabilityZone"].should.contain(region)

resp = client.describe_db_instances(DBInstanceIdentifier=db_instance_identifier)
resp["DBInstances"][0]["AvailabilityZone"].should.contain(region)


@mock_rds
def test_create_db_instance_with_availability_zone():
region = "us-east-1"
availability_zone = f"{region}c"
client = boto3.client("rds", region_name=region)
db_instance_identifier = "test-db-instance"
resp = client.create_db_instance(
DBInstanceIdentifier=db_instance_identifier,
Engine="postgres",
DBName="staging-postgres",
DBInstanceClass="db.m1.small",
AvailabilityZone=availability_zone,
)
resp["DBInstance"]["AvailabilityZone"].should.equal(availability_zone)

resp = client.describe_db_instances(DBInstanceIdentifier=db_instance_identifier)
resp["DBInstances"][0]["AvailabilityZone"].should.equal(availability_zone)