Skip to content

Ministack: Free, open-source local AWS emulator - 60+ services, Terraform compatible, real databases. Free forever. MIT licensed.

Fix RDS global cluster tag persistence (#2091)

Jay Janssenab915496ca58
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 00128bfe..30b8cdbc 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -18,6 +18,8 @@ Versioning follows [Semantic Versioning](https://semver.org/).
- **SES**: validate source/recipient addresses, content-field presence and configuration sets while accepting present empty content and ASCII/Punycode addresses.
- **Container reaping — one unreadable container no longer stops the sweep** — the boot sweep and the periodic reaper now list containers without inspecting each one, so a container whose inspect fails is skipped instead of leaving every leftover running. Reported by @iot-rocket.
- **API Gateway — management IAM actions and resource paths** — with `AUTH=true`, REST and HTTP/WebSocket API management requests use `apigateway:GET`, `POST`, `PUT`, `PATCH` and `DELETE` instead of SDK operation names. Resource ARNs preserve stage names, nested resources and collection paths, and ignore trailing slashes as AWS does, so scoped grants and explicit stage denies apply to the requested resource.
+- **RDS — global cluster tags** — `CreateGlobalCluster` now stores explicit tags and returns `TagList`. Global cluster descriptions track tag additions and removals; renaming preserves tags and deletion clears them before identifier reuse. Contributed by @jayjanssen.
+
- **AppConfig — `GetLatestConfiguration` returns an empty body when nothing changed** — it returned the full configuration on every poll. It now also returns `Version-Label` and uses `RequiredMinimumPollIntervalInSeconds` as the poll interval, and `CreateHostedConfigurationVersion` stores `VersionLabel`. Contributed by @Jolley71717.
- **AppConfig — `StopDeployment` follows the documented states** — it marked any deployment `ROLLED_BACK`. It now rolls back a `DEPLOYING` deployment (a `BAKING` one only with `AllowRevert`), reverts a completed one only with `AllowRevert` and within 72 hours (`REVERTED`), and returns `BadRequestException` otherwise. Contributed by @Jolley71717.
diff --git a/ministack/services/rds.py b/ministack/services/rds.py
index 117a5b07..355e544b 100644
--- a/ministack/services/rds.py
+++ b/ministack/services/rds.py
@@ -7845,6 +7845,10 @@ def _sync_tag_list_to_resource(arn):
if cl.get("DBClusterArn") == arn:
cl["TagList"] = list(tag_list)
return
+ for gc in _global_clusters.values():
+ if gc.get("GlobalClusterArn") == arn:
+ gc["TagList"] = list(tag_list)
+ return
for snap in _snapshots.values():
if snap.get("DBSnapshotArn") == arn:
snap["TagList"] = list(tag_list)
@@ -7941,10 +7945,12 @@ def _create_global_cluster(p):
"DeletionProtection": deletion_protection,
"GlobalClusterMembers": [],
"DatabaseName": _p(p, "DatabaseName") or "",
+ "TagList": _parse_tags(p),
}
if source_cluster:
_attach_cluster_to_global(gc, source_cluster, is_writer=True)
_global_clusters[gc_id] = gc
+ _tags[arn] = list(gc["TagList"])
return _xml(200, "CreateGlobalClusterResponse",
f"<CreateGlobalClusterResult><GlobalCluster>{_global_cluster_xml(gc)}</GlobalCluster></CreateGlobalClusterResult>")
@@ -7999,6 +8005,7 @@ def _delete_global_cluster(p):
gc["Status"] = "deleting"
del _global_clusters[gc["GlobalClusterIdentifier"]]
+ _tags.pop(gc["GlobalClusterArn"], None)
return _xml(200, "DeleteGlobalClusterResponse",
f"<DeleteGlobalClusterResult><GlobalCluster>{_global_cluster_xml(gc)}</GlobalCluster></DeleteGlobalClusterResult>")
@@ -8102,9 +8109,11 @@ def _modify_global_cluster_impl(p):
return _error("GlobalClusterAlreadyExistsFault",
f"Global cluster {new_id} already exists.", 400)
old_id = gc["GlobalClusterIdentifier"]
+ old_arn = gc["GlobalClusterArn"]
gc["GlobalClusterIdentifier"] = new_id
gc["GlobalClusterArn"] = f"arn:aws:rds::{get_account_id()}:global-cluster:{new_id}"
_global_clusters[new_id] = gc
+ _tags[gc["GlobalClusterArn"]] = _tags.pop(old_arn, [])
del _global_clusters[old_id]
for member in gc.get("GlobalClusterMembers", []):
cluster = _resolve_cluster(member["DBClusterArn"])
@@ -9160,6 +9169,10 @@ def _disable_http_endpoint(p):
def _global_cluster_xml(gc):
_refresh_global_cluster_readers(gc)
+ tag_xml = "".join(
+ f"<Tag><Key>{_esc(t['Key'])}</Key><Value>{_esc(t['Value'])}</Value></Tag>"
+ for t in gc.get("TagList", [])
+ )
member_xml = ""
for m in gc.get("GlobalClusterMembers", []):
readers_xml = "".join(f"<member>{_esc(reader)}</member>" for reader in m.get("Readers", []))
@@ -9189,7 +9202,8 @@ def _global_cluster_xml(gc):
<StorageEncrypted>{str(gc.get('StorageEncrypted', False)).lower()}</StorageEncrypted>
<DeletionProtection>{str(gc.get('DeletionProtection', False)).lower()}</DeletionProtection>
{failover_state_xml}
- <GlobalClusterMembers>{member_xml}</GlobalClusterMembers>"""
+ <GlobalClusterMembers>{member_xml}</GlobalClusterMembers>
+ <TagList>{tag_xml}</TagList>"""
# ---------------------------------------------------------------------------
diff --git a/tests/test_rds.py b/tests/test_rds.py
index 36a68461..f9fb1645 100644
--- a/tests/test_rds.py
+++ b/tests/test_rds.py
@@ -920,6 +920,60 @@ def test_rds_global_cluster_lifecycle(rds):
rds.describe_global_clusters(GlobalClusterIdentifier="test-global-1")
assert exc.value.response["Error"]["Code"] == "GlobalClusterNotFoundFault"
[email protected]("engine", ["aurora-postgresql", "aurora-mysql"])
+def test_rds_global_cluster_tags_lifecycle(rds, engine):
+ global_id = f"global-tags-{uuid.uuid4().hex[:8]}"
+ tags = [{"Key": "operator", "Value": "example&owner"},
+ {"Key": "environment", "Value": "test"}]
+ west = _regional_rds("us-west-2")
+ gc = rds.create_global_cluster(
+ GlobalClusterIdentifier=global_id, Engine=engine, Tags=tags,
+ )["GlobalCluster"]
+ arn = gc["GlobalClusterArn"]
+ try:
+ assert gc["TagList"] == tags
+ assert west.list_tags_for_resource(ResourceName=arn)["TagList"] == tags
+ assert west.describe_global_clusters(
+ GlobalClusterIdentifier=global_id,
+ )["GlobalClusters"][0]["TagList"] == tags
+
+ with pytest.raises(ClientError):
+ rds.create_global_cluster(
+ GlobalClusterIdentifier=global_id, Engine=engine,
+ Tags=[{"Key": "operator", "Value": "rejected"}],
+ )
+ assert rds.list_tags_for_resource(ResourceName=arn)["TagList"] == tags
+
+ west.add_tags_to_resource(
+ ResourceName=arn, Tags=[{"Key": "operator", "Value": "updated"}],
+ )
+ rds.remove_tags_from_resource(ResourceName=arn, TagKeys=["environment"])
+ expected = [{"Key": "operator", "Value": "updated"}]
+ assert rds.list_tags_for_resource(ResourceName=arn)["TagList"] == expected
+ assert rds.describe_global_clusters(
+ GlobalClusterIdentifier=global_id,
+ )["GlobalClusters"][0]["TagList"] == expected
+
+ renamed = global_id + "-renamed"
+ gc = rds.modify_global_cluster(
+ GlobalClusterIdentifier=global_id, NewGlobalClusterIdentifier=renamed,
+ )["GlobalCluster"]
+ global_id = renamed
+ arn = gc["GlobalClusterArn"]
+ assert gc["TagList"] == expected
+ assert west.list_tags_for_resource(ResourceName=arn)["TagList"] == expected
+ assert rds.delete_global_cluster(
+ GlobalClusterIdentifier=global_id,
+ )["GlobalCluster"]["TagList"] == expected
+ gc = rds.create_global_cluster(
+ GlobalClusterIdentifier=global_id, Engine=engine,
+ )["GlobalCluster"]
+ assert gc["TagList"] == []
+ assert rds.list_tags_for_resource(ResourceName=arn)["TagList"] == []
+ finally:
+ rds.delete_global_cluster(GlobalClusterIdentifier=global_id)
+
+
def test_rds_describe_global_clusters_member_element(rds):
"""Each cluster in DescribeGlobalClusters is a <GlobalClusterMember> element.
@@ -953,20 +1007,27 @@ def test_rds_describe_global_clusters_member_element(rds):
def test_rds_global_cluster_with_source(rds):
"""CreateGlobalCluster with SourceDBClusterIdentifier picks up engine from source."""
- rds.create_db_cluster(
+ source_tags = [{"Key": "source-only", "Value": "regional"}]
+ global_tags = [{"Key": "operator", "Value": "global"}]
+ source = rds.create_db_cluster(
DBClusterIdentifier="gc-source-cluster",
Engine="aurora-postgresql",
MasterUsername="admin",
MasterUserPassword="password123",
- )
+ Tags=source_tags,
+ )["DBCluster"]
try:
rds.create_global_cluster(
GlobalClusterIdentifier="test-global-src",
SourceDBClusterIdentifier="gc-source-cluster",
+ Tags=global_tags,
)
resp = rds.describe_global_clusters(GlobalClusterIdentifier="test-global-src")
gc = resp["GlobalClusters"][0]
assert gc["Engine"] == "aurora-postgresql"
+ assert gc["TagList"] == global_tags
+ assert rds.list_tags_for_resource(ResourceName=gc["GlobalClusterArn"])["TagList"] == global_tags
+ assert rds.list_tags_for_resource(ResourceName=source["DBClusterArn"])["TagList"] == source_tags
members = gc["GlobalClusterMembers"]
assert len(members) == 1
assert members[0]["IsWriter"] is True