diff --git a/changelogs/fragments/1315-ec2_instance-instance_type.yml b/changelogs/fragments/1315-ec2_instance-instance_type.yml new file mode 100644 index 00000000000..0df2346360c --- /dev/null +++ b/changelogs/fragments/1315-ec2_instance-instance_type.yml @@ -0,0 +1,4 @@ +breaking_changes: +- ec2_instance - the default value for ``instance_type`` has been removed. + At least one of ``instance_type`` or ``launch_template`` must be specified when launching new + instances (https://github.com/ansible-collections/amazon.aws/pull/1315). diff --git a/plugins/modules/ec2_instance.py b/plugins/modules/ec2_instance.py index 2158bc8c39e..ea77f732095 100644 --- a/plugins/modules/ec2_instance.py +++ b/plugins/modules/ec2_instance.py @@ -48,11 +48,11 @@ type: int instance_type: description: - - Instance type to use for the instance, see U(https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-types.html). + - Instance type to use for the instance, see + U(https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-types.html). - Only required when instance is not already present. - - If not specified, C(t2.micro) will be used. - - In a release after 2023-01-01 the default will be removed and either I(instance_type) or - I(launch_template) must be specificed when launching an instance. + - At least one of I(instance_type) or I(launch_template) must be specificed when launching an + instance. type: str count: description: @@ -223,6 +223,8 @@ launch_template: description: - The EC2 launch template to base instance configuration on. + - At least one of I(instance_type) or I(launch_template) must be specificed when launching an + instance. type: dict suboptions: id: @@ -1342,11 +1344,12 @@ def build_run_instance_spec(params): spec['MaxCount'] = params.get('count') spec['MinCount'] = params.get('count') - if not params.get('launch_template'): - spec['InstanceType'] = params['instance_type'] if params.get('instance_type') else 't2.micro' + if params.get("instance_type"): + spec["InstanceType"] = params["instance_type"] - if params.get('launch_template') and params.get('instance_type'): - spec['InstanceType'] = params['instance_type'] + if not (params.get("instance_type") or params.get("launch_template")): + module.fail_json("At least one of 'instance_type' and 'launch_template' " + "must be passed when launching instances.") return spec @@ -2049,11 +2052,6 @@ def main(): supports_check_mode=True ) - if not module.params.get('instance_type') and not module.params.get('launch_template'): - if module.params.get('state') not in ('absent', 'stopped'): - if module.params.get('count') or module.params.get('exact_count'): - module.deprecate("Default value instance_type has been deprecated, in the future you must set an instance_type or a launch_template", - date='2023-01-01', collection_name='amazon.aws') result = dict() if module.params.get('network'):