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

Conversation

mandar242
Copy link
Contributor

@mandar242 mandar242 commented Dec 9, 2021

SUMMARY

The launch_template option in ec2_instance has a broken condition.
Also the launch_template option defaults the instance_type to t2.micro if not specified and ignores the instance_type specified in the launch_template as said in the issue #451.

Fixes

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

ec2_instance

ADDITIONAL INFORMATION

The change does not break existing functionality as tested by the integration test run locally.
Related to the condition fix in community.aws: ansible-collections/community.aws#111

Ran the following playbook to verify the change.

# create a launch template called "test-launch-template" 
    - name: create test launch template
      community.aws.ec2_launch_template:
        template_name: test-launch-template
        image_id: ami-002068ed284xxxxxx
        instance_type: t3a.small
        network_interfaces:
          - associate_public_ip_address: no
            delete_on_termination: yes
            device_index: 0
            groups:
              - sg-xxxxxxxxxxxxxxxxxx
            subnet_id: subnet-xxxxxxxxxxxxxxxxxx
        region: us-east-2
        block_device_mappings:
          - device_name: /dev/sdb
            ebs:
              volume_size: 5
              volume_type: gp3
              delete_on_termination: true
              encrypted: yes
          - device_name: /dev/sdc
            ebs:
              volume_size: 2
              volume_type: gp2
              delete_on_termination: true
              encrypted: no
        tags:
          ssome: tags

# launch a ec2 instance using launch template created earlier - launches t3a.small instance as expected
    - name: test launch template usage
      ec2_instance:
        wait: yes
        name: "test-instance-mk-t3a.small"
        launch_template:
          name: test-launch-template
        vpc_subnet_id: subnet-xxxxxxxxxxxxxxxxxx

# launch ec2 instance using launch template created earlier - override instance type to be launch to t3.xlarge
    - name: test launch template usage - override instance type
      ec2_instance:
        wait: yes
        name: "test-instance-mk-t3.xlarge"
        instance_type: t3.xlarge
        launch_template:
          name: test-launch-template
        vpc_subnet_id: subnet-xxxxxxxxxxxxxxxxxx

@mandar242
Copy link
Contributor Author

Hi @markuman, can you take please a look at this for #451, this change would

  1. Fix the broken condition here for launch_template as fixed earlier by ec2_instance: fix launch_template condition community.aws#111
  2. Handle the default value for instance_type to not force t2.micro in use cases for launch_template.

If this approach looks like a possible solution, I can work for adding few integration tests for the change.

@mandar242 mandar242 assigned mandar242 and unassigned mandar242 Dec 9, 2021
@mandar242 mandar242 changed the title [WIP] ec2_instance: Fix launch template condition, handle launch template - default value for instance_type ec2_instance: Fix launch template condition, handle launch template - default value for instance_type Dec 16, 2021
Copy link
Member

@markuman markuman left a comment

Choose a reason for hiding this comment

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

A changelog fragment is missing.

@mandar242 mandar242 force-pushed the 451_launch_template branch 2 times, most recently from 5465923 to 70f5ad8 Compare December 17, 2021 16:54
@mandar242
Copy link
Contributor Author

recheck

Copy link

@emanuele-leopardi emanuele-leopardi left a comment

Choose a reason for hiding this comment

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

LGTM, in fact I think it doesn't make sense to have a default here. IMO, I'd rather have a failing playbook just because I forgot to pick an instance type, instead of a default value :)

@mandar242 mandar242 requested a review from jillr January 4, 2022 17:52

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

@jillr
Copy link
Collaborator

jillr commented Jan 12, 2022

recheck

@jillr
Copy link
Collaborator

jillr commented Jan 21, 2022

recheck

@jillr
Copy link
Collaborator

jillr commented Jan 24, 2022

@mandar242 you can add the gate label to this PR when the sanity/ignores-2.9.txt file is updated and the tests are passing

@alinabuzachis
Copy link
Contributor

recheck

@mandar242 mandar242 added the gate label Jan 25, 2022
Copy link
Contributor

@ansible-zuul ansible-zuul bot left a comment

Choose a reason for hiding this comment

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

LGTM!

@alinabuzachis alinabuzachis added gate and removed gate labels Jan 25, 2022
@ansible-zuul ansible-zuul bot merged commit 9a5a1eb into ansible-collections:main Jan 25, 2022
@mandar242 mandar242 deleted the 451_launch_template branch January 25, 2022 21:48
abikouo pushed a commit to abikouo/amazon.aws that referenced this pull request Oct 24, 2023
Update README, CONTRIBUTING.md: freenode -> libera.chat

Reviewed-by: Andrew Klychkov <aklychko@redhat.com>
             https://github.com/Andersson007
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants