Skip to content

Commit

Permalink
RDS: Default value for DBCluster.CopyTagsToSnapshot is False
Browse files Browse the repository at this point in the history
From the [AWS documentation](https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_CreateDBCluster.html):
"Specifies whether to copy all tags from the DB cluster to snapshots of the DB cluster. The default is not to copy them."

Interestingly, this default behavior was already covered by a test[^1], but it was only succeeding because we weren't
properly serializing the boolean value.  This commit also fixes that.

Another test, `test_add_tags_to_cluster_snapshot`, was relying on the incorrect default value being set to `True`,
so that test has been updated to explicitly request that tags be copied from the cluster to any snapshots.

[^1]: https://github.com/getmoto/moto/blob/d11b181e19b2e95255f2f663e84c4e46e20612cc/tests/test_rds/test_rds_clusters.py#L211
  • Loading branch information
bpandola authored and bblommers committed Jul 9, 2024
1 parent 91408bc commit 8165c18
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 2 additions & 2 deletions moto/rds/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def __init__(self, **kwargs: Any):
self.cluster_create_time = iso_8601_datetime_with_milliseconds()
self.copy_tags_to_snapshot = kwargs.get("copy_tags_to_snapshot")
if self.copy_tags_to_snapshot is None:
self.copy_tags_to_snapshot = True
self.copy_tags_to_snapshot = False
self.storage_type = kwargs.get("storage_type")
if self.storage_type is None:
self.storage_type = Cluster.default_storage_type(iops=self.iops)
Expand Down Expand Up @@ -413,7 +413,7 @@ def to_xml(self, initial: bool = False) -> str:
<EngineMode>{{ cluster.engine_mode }}</EngineMode>
<DeletionProtection>{{ 'true' if cluster.deletion_protection else 'false' }}</DeletionProtection>
<HttpEndpointEnabled>{{ 'true' if cluster.enable_http_endpoint else 'false' }}</HttpEndpointEnabled>
<CopyTagsToSnapshot>{{ cluster.copy_tags_to_snapshot }}</CopyTagsToSnapshot>
<CopyTagsToSnapshot>{{ 'true' if cluster.copy_tags_to_snapshot else 'false' }}</CopyTagsToSnapshot>
<CrossAccountClone>false</CrossAccountClone>
<DomainMemberships></DomainMemberships>
<EnabledCloudwatchLogsExports>
Expand Down
1 change: 1 addition & 0 deletions tests/test_rds/test_rds_clusters.py
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,7 @@ def test_add_tags_to_cluster_snapshot():
MasterUserPassword="hunter2000",
Port=1234,
Tags=[{"Key": "k1", "Value": "v1"}],
CopyTagsToSnapshot=True,
)
resp = conn.create_db_cluster_snapshot(
DBClusterIdentifier="db-primary-1", DBClusterSnapshotIdentifier="snapshot-1"
Expand Down

0 comments on commit 8165c18

Please sign in to comment.