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

Add version_description to ec2_launch_template #1763

Merged
Show file tree
Hide file tree
Changes from 5 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,2 @@
minor_changes:
- ec2_launch_template - Add argument to config `VersionDescription` of a EC2 launch template.
markuman marked this conversation as resolved.
Show resolved Hide resolved
16 changes: 14 additions & 2 deletions plugins/modules/ec2_launch_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@
- Which version should be the default when users spin up new instances based on this template? By default, the latest version will be made the default.
type: str
default: latest
version_description:
description:
- The description of a launch template version.
default: ""
type: str
markuman marked this conversation as resolved.
Show resolved Hide resolved
state:
description:
- Whether the launch template should exist or not.
Expand Down Expand Up @@ -577,7 +582,10 @@ def create_or_update(module, template_options):
out['changed'] = True
elif template and template_versions:
most_recent = sorted(template_versions, key=lambda x: x['VersionNumber'])[-1]
if lt_data == most_recent['LaunchTemplateData']:
if (
lt_data == most_recent['LaunchTemplateData']
and module.params['version_description'] == most_recent.get('VersionDescription', '')
):
out['changed'] = False
return out
try:
Expand All @@ -586,6 +594,7 @@ def create_or_update(module, template_options):
LaunchTemplateId=template['LaunchTemplateId'],
LaunchTemplateData=lt_data,
ClientToken=uuid4().hex,
VersionDescription=str(module.params['version_description']),
aws_retry=True,
)
elif module.params.get('source_version') == 'latest':
Expand All @@ -594,6 +603,7 @@ def create_or_update(module, template_options):
LaunchTemplateData=lt_data,
ClientToken=uuid4().hex,
SourceVersion=str(most_recent['VersionNumber']),
VersionDescription=str(module.params['version_description']),
aws_retry=True,
)
else:
Expand All @@ -610,6 +620,7 @@ def create_or_update(module, template_options):
LaunchTemplateData=lt_data,
ClientToken=uuid4().hex,
SourceVersion=str(source_version['VersionNumber']),
VersionDescription=str(module.params['version_description']),
aws_retry=True,
)

Expand Down Expand Up @@ -786,7 +797,8 @@ def main():
template_name=dict(aliases=['name']),
template_id=dict(aliases=['id']),
default_version=dict(default='latest'),
source_version=dict(default='latest')
source_version=dict(default='latest'),
version_description=dict(default=''),
)

arg_spec.update(template_options)
Expand Down
15 changes: 15 additions & 0 deletions tests/integration/targets/ec2_launch_template/tasks/versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,21 @@
- lt.latest_version == 4
- lt.latest_template.launch_template_data.instance_type == "c4.large"

- name: update simple instance template
ec2_launch_template:
name: "{{ resource_prefix }}-simple"
version_description: "Fix something."
register: lt

- name: instance with cpu_options created with the right options
assert:
that:
- lt is success
- lt is changed
- lt.default_version == 5
- lt.latest_version == 5
- lt.latest_template.version_description == "Fix something."

always:
- name: delete the template
ec2_launch_template:
Expand Down