Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ec2_instance: Fix launch template condition, handle launch template - default value for instance_type #587

Merged
merged 4 commits into from
Jan 25, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bugfixes:
- ec2_instance - Add a condition to handle default ```instance_type``` value
for fix breaking on instance creation with launch template (https://github.com/ansible-collections/amazon.aws/pull/587).
mandar242 marked this conversation as resolved.
Show resolved Hide resolved
17 changes: 13 additions & 4 deletions plugins/modules/ec2_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
description:
- 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.
default: t2.micro
mandar242 marked this conversation as resolved.
Show resolved Hide resolved
- If not specified, t2.micro will be used.
type: str
count:
description:
Expand Down Expand Up @@ -1232,7 +1232,7 @@ def build_top_level_options(params):

if params.get('launch_template') is not None:
spec['LaunchTemplate'] = {}
if not params.get('launch_template').get('id') or params.get('launch_template').get('name'):
if not params.get('launch_template').get('id') and not params.get('launch_template').get('name'):
module.fail_json(msg="Could not create instance with launch template. Either launch_template.name or launch_template.id parameters are required")

if params.get('launch_template').get('id') is not None:
Expand Down Expand Up @@ -1305,7 +1305,12 @@ def build_run_instance_spec(params):
spec['MaxCount'] = module.params.get('count')
spec['MinCount'] = module.params.get('count')

spec['InstanceType'] = params['instance_type']
if not module.params.get('launch_template'):
spec['InstanceType'] = params['instance_type'] if module.params.get('instance_type') else 't2.micro'

if module.params.get('launch_template') and module.params.get('instance_type'):
spec['InstanceType'] = params['instance_type']

return spec


Expand Down Expand Up @@ -1921,7 +1926,7 @@ def main():
exact_count=dict(type='int'),
image=dict(type='dict'),
image_id=dict(type='str'),
instance_type=dict(default='t2.micro', type='str'),
instance_type=dict(type='str'),
user_data=dict(type='str'),
tower_callback=dict(type='dict'),
ebs_optimized=dict(type='bool'),
Expand Down Expand Up @@ -1967,6 +1972,10 @@ def main():
],
supports_check_mode=True
)

if not module.params.get('instance_type') and not module.params.get('launch_template'):
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')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jillr Just an info, do we use date or collection version for deprecations?

@mandar242 Other than that, it looks good to me. Thank you for taking time to work on this.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alinabuzachis date, we don't expect to always have the same cadence of major collection releases

result = dict()

if module.params.get('network'):
Expand Down