Skip to content

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

fix(ec2): persist tags on CreateVpcEndpoint and flow log operations (#715)

lahmishf6cdce097820
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3226e1ab..c6172eae 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,6 +9,8 @@ Versioning follows [Semantic Versioning](https://semver.org/).
## [Unreleased]
+### Fixed
+- **EC2 `CreateVpcEndpoint` and `CreateFlowLogs` now persist `TagSpecifications`** — tags passed at creation time were silently dropped. Tags are now stored, returned by `DescribeFlowLogs`, and cleaned up on `DeleteFlowLogs`. The `fl-` prefix is also registered in the resource-type guesser so flow-log IDs are correctly resolved by the Resource Groups Tagging API.
### Added
- **IAM `UpdateAccessKey`** — enables toggling an access key between `Active` and `Inactive`, matching the two statuses the real AWS API accepts. Optional `UserName` is validated when provided.
- **IAM `GetAccessKeyLastUsed`** — returns the AWS "never used" shape (`Region`/`ServiceName` = `N/A`, no `LastUsedDate`) since MiniStack does not track per-key usage history.
diff --git a/ministack/services/ec2.py b/ministack/services/ec2.py
index b6d60437..82f7dbb3 100644
--- a/ministack/services/ec2.py
+++ b/ministack/services/ec2.py
@@ -1507,6 +1507,7 @@ def _create_vpc_endpoint(p):
"SubnetIds": _parse_member_list(p, "SubnetId"),
"OwnerId": get_account_id(),
}
+ _parse_tag_specs(p, "vpc-endpoint", vpce_id)
return _xml(200, "CreateVpcEndpointResponse",
_vpce_fields_xml(_vpc_endpoints[vpce_id], tag="vpcEndpoint"))
@@ -2653,6 +2654,7 @@ def _guess_resource_type(resource_id):
"snap-": "snapshot",
"acl-": "network-acl",
"nat-": "natgateway",
+ "fl-": "flow-log",
"dopt-": "dhcp-options",
"eigw-": "egress-only-internet-gateway",
"lt-": "launch-template",
@@ -2945,6 +2947,7 @@ def _create_flow_logs(params):
"FlowLogStatus": "ACTIVE",
"CreationTime": _now_ts(),
}
+ _parse_tag_specs(params, "flow-log", fl_id)
created.append(fl_id)
ids_xml = "".join(f"<item>{fid}</item>" for fid in created)
return _xml(200, "CreateFlowLogsResponse",
@@ -2970,6 +2973,7 @@ def _describe_flow_logs(params):
<logDestination>{fl.get('LogDestination','')}</logDestination>
<flowLogStatus>{fl['FlowLogStatus']}</flowLogStatus>
<creationTime>{fl['CreationTime']}</creationTime>
+ {_tag_set_xml(fl['FlowLogId'])}
</item>"""
return _xml(200, "DescribeFlowLogsResponse", f"<flowLogSet>{items}</flowLogSet>")
@@ -2978,6 +2982,7 @@ def _delete_flow_logs(params):
ids = _parse_member_list(params, "FlowLogId")
for fid in ids:
_flow_logs.pop(fid, None)
+ _tags.pop(fid, None)
return _xml(200, "DeleteFlowLogsResponse", "<unsuccessful/>")
diff --git a/tests/test_ec2.py b/tests/test_ec2.py
index c9d708c8..701ae258 100644
--- a/tests/test_ec2.py
+++ b/tests/test_ec2.py
@@ -629,6 +629,28 @@ def test_ec2_vpc_endpoint_crud(ec2):
ec2.delete_vpc(VpcId=vpc_id)
+
+def test_ec2_vpc_endpoint_tags(ec2):
+ vpc_id = ec2.create_vpc(CidrBlock="10.41.0.0/16")["Vpc"]["VpcId"]
+
+ vpce_id = ec2.create_vpc_endpoint(
+ VpcId=vpc_id,
+ ServiceName="com.amazonaws.us-east-1.s3",
+ VpcEndpointType="Gateway",
+ TagSpecifications=[{
+ "ResourceType": "vpc-endpoint",
+ "Tags": [{"Key": "Env", "Value": "test"}, {"Key": "Team", "Value": "infra"}],
+ }],
+ )["VpcEndpoint"]["VpcEndpointId"]
+
+ desc = ec2.describe_vpc_endpoints(VpcEndpointIds=[vpce_id])
+ tags = {t["Key"]: t["Value"] for t in desc["VpcEndpoints"][0].get("Tags", [])}
+ assert tags == {"Env": "test", "Team": "infra"}
+
+ ec2.delete_vpc_endpoints(VpcEndpointIds=[vpce_id])
+ ec2.delete_vpc(VpcId=vpc_id)
+
+
def test_ec2_describe_vpc_endpoint_services(ec2):
resp = ec2.describe_vpc_endpoint_services()
names = resp["ServiceNames"]
@@ -770,6 +792,34 @@ def test_ec2_flow_logs_crud(ec2):
desc2 = ec2.describe_flow_logs(FlowLogIds=fl_ids)
assert len(desc2["FlowLogs"]) == 0
+
+def test_ec2_flow_log_tags(ec2):
+ vpc = ec2.create_vpc(CidrBlock="10.105.0.0/16")
+ vpc_id = vpc["Vpc"]["VpcId"]
+
+ fl_ids = ec2.create_flow_logs(
+ ResourceIds=[vpc_id],
+ ResourceType="VPC",
+ TrafficType="ALL",
+ LogDestinationType="cloud-watch-logs",
+ LogGroupName="/aws/vpc/flowlogs-tags",
+ TagSpecifications=[{
+ "ResourceType": "flow-log",
+ "Tags": [{"Key": "Project", "Value": "ministack"}],
+ }],
+ )["FlowLogIds"]
+
+ desc = ec2.describe_flow_logs(FlowLogIds=fl_ids)
+ tags = {t["Key"]: t["Value"] for t in desc["FlowLogs"][0].get("Tags", [])}
+ assert tags == {"Project": "ministack"}
+
+ ec2.delete_flow_logs(FlowLogIds=fl_ids)
+ tag_resp = ec2.describe_tags(Filters=[{"Name": "resource-id", "Values": fl_ids}])
+ assert tag_resp["Tags"] == []
+
+ ec2.delete_vpc(VpcId=vpc_id)
+
+
def test_ec2_vpc_peering_crud(ec2):
vpc1 = ec2.create_vpc(CidrBlock="10.105.0.0/16")
vpc2 = ec2.create_vpc(CidrBlock="10.106.0.0/16")