diff --git a/moto/ec2/models/instances.py b/moto/ec2/models/instances.py index 5f438e5d9..1ec92e833 100644 --- a/moto/ec2/models/instances.py +++ b/moto/ec2/models/instances.py @@ -112,6 +112,7 @@ class Instance(TaggedEC2Resource, BotoInstance, CloudFormationModel): self.instance_initiated_shutdown_behavior = ( kwargs.get("instance_initiated_shutdown_behavior") or "stop" ) + self.hibernation_options = kwargs.get("hibernation_options") self.sriov_net_support = "simple" self._spot_fleet_id = kwargs.get("spot_fleet_id", None) self._fleet_id = kwargs.get("fleet_id", None) diff --git a/moto/ec2/responses/instances.py b/moto/ec2/responses/instances.py index 60b2e27ca..4bc68e2d2 100644 --- a/moto/ec2/responses/instances.py +++ b/moto/ec2/responses/instances.py @@ -72,6 +72,7 @@ class InstanceResponse(EC2BaseResponse): "InstanceInitiatedShutdownBehavior" ), "launch_template": self._get_multi_param_dict("LaunchTemplate"), + "hibernation_options": self._get_multi_param_dict("HibernationOptions"), } if len(kwargs["nics"]) and kwargs["subnet_id"]: raise InvalidParameterCombination( @@ -465,6 +466,11 @@ EC2_RUN_INSTANCES = """ + + {% endif %} {% for tag in instance.get_tags() %} diff --git a/tests/test_ec2/test_instances.py b/tests/test_ec2/test_instances.py index 8412e14d9..432e84bc1 100644 --- a/tests/test_ec2/test_instances.py +++ b/tests/test_ec2/test_instances.py @@ -1129,13 +1129,21 @@ def test_run_instance_with_security_group_id(): @mock_ec2 -def test_run_instance_with_instance_type(): +@pytest.mark.parametrize("hibernate", [True, False]) +def test_run_instance_with_additional_args(hibernate): ec2 = boto3.resource("ec2", region_name="us-east-1") instance = ec2.create_instances( - ImageId=EXAMPLE_AMI_ID, MinCount=1, MaxCount=1, InstanceType="t1.micro" + ImageId=EXAMPLE_AMI_ID, + MinCount=1, + MaxCount=1, + InstanceType="t1.micro", + Placement={"AvailabilityZone": "us-east-1b"}, + HibernationOptions={"Configured": hibernate}, )[0] instance.instance_type.should.equal("t1.micro") + instance.placement.should.have.key("AvailabilityZone").equal("us-east-1b") + instance.hibernation_options.should.equal({"Configured": hibernate}) @mock_ec2 @@ -1146,19 +1154,6 @@ def test_run_instance_with_default_placement(): instance.placement.should.have.key("AvailabilityZone").equal("us-east-1a") -@mock_ec2 -def test_run_instance_with_placement(): - ec2 = boto3.resource("ec2", region_name="us-east-1") - instance = ec2.create_instances( - ImageId=EXAMPLE_AMI_ID, - MinCount=1, - MaxCount=1, - Placement={"AvailabilityZone": "us-east-1b"}, - )[0] - - instance.placement.should.have.key("AvailabilityZone").equal("us-east-1b") - - @mock_ec2 @mock.patch( "moto.ec2.models.instances.settings.EC2_ENABLE_INSTANCE_TYPE_VALIDATION",