Skip to content

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

fix(logs): resolve vended-delivery ARNs in TagResource/UntagResource/ListTagsForResource (#1318)

t-rech492ac594b17c
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d530ff16..79c826ea 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,7 @@ Versioning follows [Semantic Versioning](https://semver.org/).
## [Unreleased]
### Fixed
+- **CloudWatch Logs — ARN-based tag operations resolve vended-delivery resources** — `TagResource`, `UntagResource`, and `ListTagsForResource` only resolved log-group ARNs, so the AWS provider's read-after-create on `aws_cloudwatch_log_delivery_source` / `aws_cloudwatch_log_delivery_destination` / `aws_cloudwatch_log_delivery` failed with `ResourceNotFoundException` and broke `terraform apply` of any stack using EventBridge bus logging (the community EventBridge module ≥ v4.1 provisions the trio). All three operations now resolve the delivery records' tags.
- **Route 53 — `ChangeResourceRecordSets` `DELETE` now requires the values provided to match the current values** — a `DELETE` matched only on name, type, and set identifier, so a delete carrying a stale TTL or stale record values silently removed the live record. Real Route 53 requires the values in a `DELETE` to match the current record exactly and rejects the whole batch with `InvalidChangeBatch` otherwise — the compare-and-swap semantics that guarded-delete workflows (delete only if the record still holds the values I last observed) rely on to detect concurrent modification, which the emulator's silent success defeated. A mismatched `DELETE` now fails the batch atomically with the AWS-shaped message (`Tried to delete resource record set [name='…', type='…'] but the values provided do not match the current values`); record values are compared as an unordered set, so the same values in a different order still match. Contributed by @jayjanssen.
## [1.4.14] — 2026-08-07
diff --git a/ministack/services/cloudwatch_logs.py b/ministack/services/cloudwatch_logs.py
index fe8c9094..af8787c3 100644
--- a/ministack/services/cloudwatch_logs.py
+++ b/ministack/services/cloudwatch_logs.py
@@ -1301,40 +1301,60 @@ def _list_tags_log_group(data):
# Tags – modern ARN-based APIs
# ---------------------------------------------------------------------------
+def _resolve_tag_record_by_arn(arn: str):
+ """Resolve a logs ARN to the mutable dict holding its ``tags``. The
+ ARN-based tag operations accept log groups AND the vended-delivery trio
+ (delivery sources, delivery destinations, deliveries) — the AWS provider
+ reads tags back on every one of them after create."""
+ group = _resolve_group_by_arn(arn)
+ if group:
+ return _log_groups[group].setdefault("tags", {})
+ for marker, store in (
+ (":delivery-source:", _delivery_sources),
+ (":delivery-destination:", _delivery_destinations),
+ (":delivery:", _deliveries),
+ ):
+ if marker in arn:
+ record = store.get(arn.rsplit(":", 1)[-1])
+ if record is not None:
+ return record.setdefault("tags", {})
+ return None
+
+
def _tag_resource(data):
arn = data.get("resourceArn", "")
- group = _resolve_group_by_arn(arn)
- if not group:
+ tags = _resolve_tag_record_by_arn(arn)
+ if tags is None:
return error_response_json(
"ResourceNotFoundException",
f"The specified resource does not exist: {arn}", 400,
)
- _log_groups[group]["tags"].update(data.get("tags", {}))
+ tags.update(data.get("tags", {}))
return json_response({})
def _untag_resource(data):
arn = data.get("resourceArn", "")
- group = _resolve_group_by_arn(arn)
- if not group:
+ tags = _resolve_tag_record_by_arn(arn)
+ if tags is None:
return error_response_json(
"ResourceNotFoundException",
f"The specified resource does not exist: {arn}", 400,
)
for key in data.get("tagKeys", []):
- _log_groups[group]["tags"].pop(key, None)
+ tags.pop(key, None)
return json_response({})
def _list_tags_for_resource(data):
arn = data.get("resourceArn", "")
- group = _resolve_group_by_arn(arn)
- if not group:
+ tags = _resolve_tag_record_by_arn(arn)
+ if tags is None:
return error_response_json(
"ResourceNotFoundException",
f"The specified resource does not exist: {arn}", 400,
)
- return json_response({"tags": dict(_log_groups[group]["tags"])})
+ return json_response({"tags": dict(tags)})
# ---------------------------------------------------------------------------
diff --git a/tests/test_cloudwatch_logs.py b/tests/test_cloudwatch_logs.py
index a5fea064..fb2b3979 100644
--- a/tests/test_cloudwatch_logs.py
+++ b/tests/test_cloudwatch_logs.py
@@ -1576,3 +1576,24 @@ def test_logs_describe_streams_on_nonexistent_group_carries_errortype(logs):
logs.describe_log_streams(logGroupName="missing-lg")
assert exc.value.response["Error"]["Code"] == "ResourceNotFoundException"
assert exc.value.response["ResponseMetadata"]["HTTPHeaders"].get("x-amzn-errortype") == "ResourceNotFoundException"
+
+
+def test_logs_delivery_source_tag_round_trip(logs):
+ """ARN-based tag operations resolve the vended-delivery records too — the
+ AWS provider reads tags back on every aws_cloudwatch_log_delivery_* after
+ create."""
+ src_name = "qa-logs-ds-tags"
+ put = logs.put_delivery_source(
+ name=src_name,
+ resourceArn="arn:aws:events:us-east-1:000000000000:event-bus/qa-ds-tags-bus",
+ logType="APPLICATION_LOGS",
+ tags={"env": "qa"},
+ )
+ arn = put["deliverySource"]["arn"]
+
+ assert logs.list_tags_for_resource(resourceArn=arn)["tags"] == {"env": "qa"}
+ logs.tag_resource(resourceArn=arn, tags={"team": "events"})
+ assert logs.list_tags_for_resource(resourceArn=arn)["tags"] == {"env": "qa", "team": "events"}
+ logs.untag_resource(resourceArn=arn, tagKeys=["env"])
+ assert logs.list_tags_for_resource(resourceArn=arn)["tags"] == {"team": "events"}
+ logs.delete_delivery_source(name=src_name)