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: Add count parameter to ec2_instance #539

Merged

Conversation

mandar242
Copy link
Contributor

@mandar242 mandar242 commented Oct 19, 2021

SUMMARY

UPDATE: Added count and exact_count parameters to ec2_instance instead of min_count and max_count.

Adding min_count and max_count parameter to ec2_instance.

Fixes #536.

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

ec2_instance

@ansibullbot
Copy link

@ansibullbot ansibullbot added WIP Work in progress feature This issue/PR relates to a feature request integration tests/integration module module needs_triage plugins plugin (any type) tests tests labels Oct 19, 2021
@mandar242 mandar242 changed the title [WIP] ec2_instance: Add count parameter to ec2_instance ec2_instance: Add count parameter to ec2_instance Oct 25, 2021
@ansibullbot ansibullbot added community_review and removed WIP Work in progress labels Oct 25, 2021
@ansibullbot
Copy link

@mandar242 this PR contains the following merge commits:

Please rebase your branch to remove these commits.

click here for bot help

@ansibullbot ansibullbot added merge_commit This PR contains at least one merge commit. Please resolve! needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html and removed community_review labels Oct 25, 2021
@ansibullbot ansibullbot added community_review and removed merge_commit This PR contains at least one merge commit. Please resolve! needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html labels Oct 25, 2021
Copy link
Collaborator

@jillr jillr left a comment

Choose a reason for hiding this comment

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

Good work, thanks @mandar242!

plugins/modules/ec2_instance.py Outdated Show resolved Hide resolved
plugins/modules/ec2_instance.py Outdated Show resolved Hide resolved
plugins/modules/ec2_instance.py Outdated Show resolved Hide resolved
Copy link
Contributor

@tremble tremble left a comment

Choose a reason for hiding this comment

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

Thanks for this @mandar242

plugins/modules/ec2_instance.py Outdated Show resolved Hide resolved
plugins/modules/ec2_instance.py Outdated Show resolved Hide resolved
plugins/modules/ec2_instance.py Outdated Show resolved Hide resolved
Copy link
Contributor

@tremble tremble left a comment

Choose a reason for hiding this comment

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

Hi @mandar242,
(following up on a private conversation so the reasoning behind any new logic can be publicly followed)

Usually, with Ansible we try to default to things being idempotent, and update an existing object rather than always triggering a change.  Given this context the way I would generally have interpreted "Max" and "Min" for the ec2_instance module is that we want the total number of matching instances to be between the two values: something approximating an Ansible-managed alternative to an AutoScalingGroup.

Currently, we have users migrating from the old ec2 module [1] which has exact_count and countcount would always spawn instances (the behaviour you've implemented), but exact_count would try to ensure that the total number of matching (filters) instances is exact_count (the behaviour I thought you were trying to implement).

The fact that I misinterpreted what you had tried to implement things (having generally used exact_count rather than count) means that users probably will too.

Rather than exposing max_count and min_count, I'd recommend:

  • count (int - default 1): number of instances expected to match the filters, mimicking ec2.py's "exact_count" by default.
  • always_launch (bool - default false): if set to true then always trigger a launch. (as you do today if count > 1)

This means that the count=1 behaviour is much closer to the count>1 behaviour, it also means if the user really did want to always launch a new instance, they can now also launch them one at a time if they wanted.

@mandar242 mandar242 changed the title [WIP] ec2_instance: Add count parameter to ec2_instance ec2_instance: Add count parameter to ec2_instance Nov 15, 2021
plugins/modules/ec2_instance.py Show resolved Hide resolved

elif current_count < exact_count:
to_launch = exact_count - current_count
module.params['to_launch'] = to_launch
Copy link
Contributor

Choose a reason for hiding this comment

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

We could overwrite module.params['count'] here to avoid the extra code path in build_run_instance_spec

@jillr do you have any opinions 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.

I generally don't like overwriting module.params, I worry that it's asking for issues down the road when we make some other change that uses count and expects it to be whatever the user originally specified. I think I'd rather have the extra conditional?

plugins/modules/ec2_instance.py Outdated Show resolved Hide resolved
plugins/modules/ec2_instance.py Outdated Show resolved Hide resolved
plugins/modules/ec2_instance.py Show resolved Hide resolved
Copy link
Collaborator

@jillr jillr left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for all your work on this @mandar242!


elif current_count < exact_count:
to_launch = exact_count - current_count
module.params['to_launch'] = to_launch
Copy link
Collaborator

Choose a reason for hiding this comment

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

I generally don't like overwriting module.params, I worry that it's asking for issues down the road when we make some other change that uses count and expects it to be whatever the user originally specified. I think I'd rather have the extra conditional?

@jillr jillr added the gate label Nov 29, 2021
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!

@tremble tremble added gate and removed gate labels Nov 30, 2021
@ansible-zuul ansible-zuul bot merged commit 760186c into ansible-collections:main Nov 30, 2021
@tremble tremble added the backport-2 PR should be backported to the stable-2 branch label Nov 30, 2021
@patchback
Copy link

patchback bot commented Nov 30, 2021

Backport to stable-2: 💚 backport PR created

✅ Backport PR branch: patchback/backports/stable-2/760186c5c576548cdb4bb7a4e2f6a79d9c1f3b44/pr-539

Backported as #580

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

patchback bot pushed a commit that referenced this pull request Nov 30, 2021
ec2_instance: Add count parameter to ec2_instance

SUMMARY

Adding min_count and max_count parameter to ec2_instance.
Fixes #536.
ISSUE TYPE

Feature Pull Request

COMPONENT NAME

ec2_instance

Reviewed-by: Jill R <None>
Reviewed-by: Mark Chappell <None>
Reviewed-by: Mandar Kulkarni <mandar242@gmail.com>
Reviewed-by: None <None>
(cherry picked from commit 760186c)
ansible-zuul bot pushed a commit that referenced this pull request Nov 30, 2021
Add missing version_added to ec2_instance.py

SUMMARY
Realised after #539 merged that we didn't add version_added
ISSUE TYPE

Docs Pull Request

COMPONENT NAME
ec2_instance
ADDITIONAL INFORMATION

Reviewed-by: Alina Buzachis <None>
Reviewed-by: None <None>
tremble pushed a commit that referenced this pull request Dec 1, 2021
ec2_instance: Add count parameter to ec2_instance

SUMMARY

Adding min_count and max_count parameter to ec2_instance.
Fixes #536.
ISSUE TYPE

Feature Pull Request

COMPONENT NAME

ec2_instance

Reviewed-by: Jill R <None>
Reviewed-by: Mark Chappell <None>
Reviewed-by: Mandar Kulkarni <mandar242@gmail.com>
Reviewed-by: None <None>
(cherry picked from commit 760186c)

Co-authored-by: Mandar Kulkarni <mandar242@gmail.com>
patchback bot pushed a commit that referenced this pull request Dec 3, 2021
Add missing version_added to ec2_instance.py

SUMMARY
Realised after #539 merged that we didn't add version_added
ISSUE TYPE

Docs Pull Request

COMPONENT NAME
ec2_instance
ADDITIONAL INFORMATION

Reviewed-by: Alina Buzachis <None>
Reviewed-by: None <None>
(cherry picked from commit cf2b9aa)
tremble added a commit that referenced this pull request Dec 3, 2021
Add missing version_added to ec2_instance.py

SUMMARY
Realised after #539 merged that we didn't add version_added
ISSUE TYPE

Docs Pull Request

COMPONENT NAME
ec2_instance
ADDITIONAL INFORMATION

Reviewed-by: Alina Buzachis <None>
Reviewed-by: None <None>
(cherry picked from commit cf2b9aa)

Co-authored-by: Mark Chappell <mchappel@redhat.com>
@mandar242 mandar242 deleted the ec2_instance_count_param branch December 26, 2021 16:40
abikouo pushed a commit to abikouo/amazon.aws that referenced this pull request Oct 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-2 PR should be backported to the stable-2 branch community_review feature This issue/PR relates to a feature request integration tests/integration module module plugins plugin (any type) tests tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ec2_instance module doesn't have count
5 participants