Skip to content

Commit

Permalink
ec2_instance - Drop default value for instance_type
Browse files Browse the repository at this point in the history
  • Loading branch information
tremble committed Jan 4, 2023
1 parent b120830 commit 531787c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
4 changes: 4 additions & 0 deletions changelogs/fragments/1315-ec2_instance-instance_type.yml
Original file line number Diff line number Diff line change
@@ -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).
24 changes: 11 additions & 13 deletions plugins/modules/ec2_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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'):
Expand Down

0 comments on commit 531787c

Please sign in to comment.