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_asg: Add functionality to detach specified instances from ASG #933

Conversation

mandar242
Copy link
Contributor

@mandar242 mandar242 commented Feb 10, 2022

SUMMARY

Adds feature to detach specified instances from a AutoScalingGroup rather than terminating them directly.
Detached instances are not terminated and can be managed independently.

Implements #649

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

ec2_asg

ADDITIONAL INFORMATION

Makes use of
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/autoscaling.html#AutoScaling.Client.detach_instances

@ansibullbot
Copy link

@ansibullbot ansibullbot added WIP Work in progress feature This issue/PR relates to a feature request module module needs_triage plugins plugin (any type) labels Feb 10, 2022
Copy link
Contributor

@alinabuzachis alinabuzachis left a comment

Choose a reason for hiding this comment

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

@mandar242 Thank you for working on this. You should add some integration tests for these features and a changelog fragment.

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

@alinabuzachis alinabuzachis left a comment

Choose a reason for hiding this comment

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

@mandar242 You also would need a changelog fragment and integration tests for these options.

@ansibullbot ansibullbot added integration tests/integration tests tests labels Feb 16, 2022
@mandar242 mandar242 changed the title [WIP] ec2_asg: Add functionality to detach specified instances from ASG ec2_asg: Add functionality to detach specified instances from ASG Feb 21, 2022
@ansibullbot ansibullbot added community_review and removed WIP Work in progress labels Feb 21, 2022
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.

Two minor nits on some error messages, otherwise the code looks good - thanks @mandar242

plugins/modules/ec2_asg.py Outdated Show resolved Hide resolved
plugins/modules/ec2_asg.py Outdated Show resolved Hide resolved
@jillr
Copy link
Collaborator

jillr commented Feb 22, 2022

recheck

@jillr
Copy link
Collaborator

jillr commented Feb 22, 2022

afaict the timeout is just because we have to wait for instances on several tasks and the API was being slow when the tests ran.

@mandar242
Copy link
Contributor Author

recheck

Copy link
Contributor

@jatorcasso jatorcasso left a comment

Choose a reason for hiding this comment

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

Left some minor grammar fixes - LGTM!

plugins/modules/ec2_asg.py Outdated Show resolved Hide resolved
def detach(connection):
group_name = module.params.get('name')
detach_instances = module.params.get('detach_instances')
as_group = describe_autoscaling_groups(connection, group_name)[0]
Copy link
Contributor

Choose a reason for hiding this comment

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

is there a case where multiple autoscaling groups are returned here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think as we are passing only single group name, we will only single auto scaling group's info.

Copy link
Contributor

Choose a reason for hiding this comment

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

just checking! Wasnt sure if there were cases where multiple groups had the same name

Copy link
Collaborator

Choose a reason for hiding this comment

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

ASG name is unique within a region and account. Since we can only act on one region and account at a time, this works well.

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.

The code lgtm, thanks very much @mandar242! I'll hold off on tagging this to merge over the weekend in case @alinabuzachis would like to update her review but with CI passing I think this is ready.

@alinabuzachis alinabuzachis added the mergeit Merge the PR (SoftwareFactory) label Feb 26, 2022
@softwarefactory-project-zuul softwarefactory-project-zuul bot merged commit 44d2b30 into ansible-collections:main Feb 26, 2022
@mandar242 mandar242 deleted the 649_ec2_asg_detach_instance branch February 26, 2022 20:27
alinabuzachis pushed a commit to alinabuzachis/community.aws that referenced this pull request Mar 11, 2022
…sible-collections#933)

ec2_asg: Add functionality to detach specified instances from ASG 

SUMMARY

Adds feature to detach specified instances from a AutoScalingGroup rather than terminating them directly.
Detached instances are not terminated and can be managed independently.

Implements ansible-collections#649
ISSUE TYPE


Feature Pull Request

COMPONENT NAME

ec2_asg
ADDITIONAL INFORMATION


Makes use of
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/autoscaling.html#AutoScaling.Client.detach_instances

Reviewed-by: Alina Buzachis <None>
Reviewed-by: Mandar Kulkarni <mandar242@gmail.com>
Reviewed-by: Jill R <None>
Reviewed-by: Joseph Torcasso <None>
softwarefactory-project-zuul bot pushed a commit that referenced this pull request Mar 30, 2022
ec2_asg: backport PRs 960 and 933

SUMMARY

ec2_asg: backports PRs #960  and #933

ISSUE TYPE


Bugfix Pull Request
Docs Pull Request
Feature Pull Request
New Module Pull Request

COMPONENT NAME

ADDITIONAL INFORMATION

Reviewed-by: Markus Bergholz <git@osuv.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community_review feature This issue/PR relates to a feature request integration tests/integration mergeit Merge the PR (SoftwareFactory) module module plugins plugin (any type) tests tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants