From 3e90012509300c4a0fd8083370f50d11a0cdb705 Mon Sep 17 00:00:00 2001 From: Brian Pandola Date: Tue, 19 Mar 2024 16:51:34 -0700 Subject: [PATCH] Add StateTransitionReason to ec2:DescribeInstances response (#7495) --- moto/ec2/responses/instances.py | 2 +- tests/test_ec2/test_instances.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/moto/ec2/responses/instances.py b/moto/ec2/responses/instances.py index 479cc3edb..78b1ccfc9 100644 --- a/moto/ec2/responses/instances.py +++ b/moto/ec2/responses/instances.py @@ -463,7 +463,7 @@ INSTANCE_TEMPLATE = """ {{ instance.private_dns }} {{ instance.public_dns }} {{ instance.public_dns }} - + {{ instance._reason }} {% if instance.key_name is not none %} {{ instance.key_name }} {% endif %} diff --git a/tests/test_ec2/test_instances.py b/tests/test_ec2/test_instances.py index 161938d7b..7cd80dcbb 100644 --- a/tests/test_ec2/test_instances.py +++ b/tests/test_ec2/test_instances.py @@ -973,6 +973,7 @@ def test_instance_start_and_stop(): instance1.reload() assert instance1.state == {"Code": 80, "Name": "stopped"} + assert instance1.state_transition_reason.startswith("User initiated") with pytest.raises(ClientError) as ex: client.start_instances(InstanceIds=[instance1.id], DryRun=True)