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 purge_tags to AutoScalingGroups. #960

Merged

Conversation

mandar242
Copy link
Contributor

@mandar242 mandar242 commented Mar 2, 2022

SUMMARY

Add purge_tags to ec2_asg module.

Fixes #481.

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

ec2_asg

ADDITIONAL INFORMATION

There was another PR (currently closed) #482 - with similar functionality but I'm not sure if having modules to handle tags for individual services/modules is a good way to have this functionality. It will certainly cause increase in number of modules.
Hence tried modifying existing ec2_asg module to be able to do this.

This utilizes underlying API calls to:

https://docs.aws.amazon.com/autoscaling/ec2/APIReference/API_DescribeTags.html
https://docs.aws.amazon.com/autoscaling/ec2/APIReference/API_CreateOrUpdateTags.html
https://docs.aws.amazon.com/autoscaling/ec2/APIReference/API_DeleteTags.html

@ansibullbot
Copy link

@ansibullbot ansibullbot added community_review feature This issue/PR relates to a feature request integration tests/integration module module needs_triage plugins plugin (any type) tests tests labels Mar 2, 2022
@softwarefactory-project-zuul

This comment was marked as outdated.

@softwarefactory-project-zuul

This comment was marked as outdated.

@softwarefactory-project-zuul

This comment was marked as outdated.

@softwarefactory-project-zuul

This comment was marked as outdated.

@mandar242 mandar242 changed the title ec2_asg: Add ability to manage tags on AutoScalingGroups WIP: ec2_asg: Add ability to manage tags on AutoScalingGroups Mar 2, 2022
@ansibullbot ansibullbot added the WIP Work in progress label Mar 2, 2022
@mandar242 mandar242 changed the title WIP: ec2_asg: Add ability to manage tags on AutoScalingGroups ec2_asg: Add ability to manage tags on AutoScalingGroups Mar 2, 2022
@mandar242 mandar242 requested review from alinabuzachis and jillr March 2, 2022 22:08
@ansibullbot ansibullbot removed the WIP Work in progress label Mar 2, 2022
plugins/modules/ec2_asg.py Outdated Show resolved Hide resolved
@mandar242 mandar242 requested a review from alinabuzachis March 5, 2022 17:01
@mandar242 mandar242 added mergeit Merge the PR (SoftwareFactory) and removed needs_triage labels Mar 10, 2022
@alinabuzachis alinabuzachis added the backport-3 PR should be backported to the stable-3 branch label Mar 10, 2022
@softwarefactory-project-zuul

This comment was marked as outdated.

@mandar242 mandar242 added mergeit Merge the PR (SoftwareFactory) and removed mergeit Merge the PR (SoftwareFactory) labels Mar 10, 2022
@mandar242 mandar242 added mergeit Merge the PR (SoftwareFactory) and removed mergeit Merge the PR (SoftwareFactory) labels Mar 11, 2022
@softwarefactory-project-zuul softwarefactory-project-zuul bot merged commit 1ca997a into ansible-collections:main Mar 11, 2022
@patchback
Copy link

patchback bot commented Mar 11, 2022

Backport to stable-3: 💔 cherry-picking failed — conflicts found

❌ Failed to cleanly apply 1ca997a on top of patchback/backports/stable-3/1ca997af9c7bb31197d7951d3d395c9cc48ab842/pr-960

Backporting merged PR #960 into main

  1. Ensure you have a local repo clone of your fork. Unless you cloned it
    from the upstream, this would be your origin remote.
  2. Make sure you have an upstream repo added as a remote too. In these
    instructions you'll refer to it by the name upstream. If you don't
    have it, here's how you can add it:
    $ git remote add upstream https://github.com/ansible-collections/community.aws.git
  3. Ensure you have the latest copy of upstream and prepare a branch
    that will hold the backported code:
    $ git fetch upstream
    $ git checkout -b patchback/backports/stable-3/1ca997af9c7bb31197d7951d3d395c9cc48ab842/pr-960 upstream/stable-3
  4. Now, cherry-pick PR ec2_asg: Add purge_tags to AutoScalingGroups. #960 contents into that branch:
    $ git cherry-pick -x 1ca997af9c7bb31197d7951d3d395c9cc48ab842
    If it'll yell at you with something like fatal: Commit 1ca997af9c7bb31197d7951d3d395c9cc48ab842 is a merge but no -m option was given., add -m 1 as follows intead:
    $ git cherry-pick -m1 -x 1ca997af9c7bb31197d7951d3d395c9cc48ab842
  5. At this point, you'll probably encounter some merge conflicts. You must
    resolve them in to preserve the patch from PR ec2_asg: Add purge_tags to AutoScalingGroups. #960 as close to the
    original as possible.
  6. Push this branch to your fork on GitHub:
    $ git push origin patchback/backports/stable-3/1ca997af9c7bb31197d7951d3d395c9cc48ab842/pr-960
  7. Create a PR, ensure that the CI is green. If it's not — update it so that
    the tests and any other checks pass. This is it!
    Now relax and wait for the maintainers to process your pull request
    when they have some cycles to do reviews. Don't worry — they'll tell you if
    any improvements are necessary when the time comes!

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

alinabuzachis pushed a commit to alinabuzachis/community.aws that referenced this pull request Mar 11, 2022
ec2_asg: Add purge_tags to AutoScalingGroups.

SUMMARY

Add purge_tags to ec2_asg module.

Fixes ansible-collections#481.
ISSUE TYPE


Feature Pull Request

COMPONENT NAME

ec2_asg
ADDITIONAL INFORMATION

There was another PR (currently closed) ansible-collections#482 - with similar functionality but I'm not sure if having modules to handle tags for individual services/modules is a good way to have this functionality. It will certainly cause increase in number of modules.
Hence tried modifying existing ec2_asg module to be able to do this.

This utilizes underlying API calls to:
https://docs.aws.amazon.com/autoscaling/ec2/APIReference/API_DescribeTags.html
https://docs.aws.amazon.com/autoscaling/ec2/APIReference/API_CreateOrUpdateTags.html
https://docs.aws.amazon.com/autoscaling/ec2/APIReference/API_DeleteTags.html

Reviewed-by: Alina Buzachis <None>
Reviewed-by: Jill R <None>
Reviewed-by: Mandar Kulkarni <[email protected]>
@mandar242 mandar242 deleted the ec2_asg_tags branch March 29, 2022 22:23
@mandar242 mandar242 restored the ec2_asg_tags branch March 29, 2022 22:23
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 <[email protected]>
@mandar242 mandar242 deleted the ec2_asg_tags branch April 12, 2022 00:56
description:
- If C(true), existing tags will be purged from the resource to match exactly what is defined by I(tags) parameter.
- If the I(tags) parameter is not set then tags will not be modified.
default: true
Copy link

Choose a reason for hiding this comment

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

Forgive me for commenting on an already merged PR, but I just found out about this from a complete breakage of all ansible AWS services that use tags.

Why was default=True chosen, for a new field that no one was using previously, deemed a good idea?

Now, everything that touches any asset that uses tags MUST now add a purge_tags: False just to leave things as they are??

Otherwise all tags are deleted???

Existing use case to scale in/out an ASG, and touch nothing else:

- community.aws.ec2_asg:
    name: "{{ item.auto_scaling_group_name }}"
    min_size: "{{ count }}"
    max_size: "{{ count }}"
    desired_capacity: "{{ count }}"
    region: eu-central-1

Now, the above and strips all tags as well.

Given that most ASG tags are used to propagate context information to the ec2 instances, this now destroys all context information for the ASG and the instances it creates have no information about the runtime context.

How is that the "principle of least surprising behavior"?

This now requires adding the purge_tags: False everywhere where tags could be impacted.

- community.aws.ec2_asg:
    name: "{{ item.auto_scaling_group_name }}"
    min_size: "{{ count }}"
    max_size: "{{ count }}"
    desired_capacity: "{{ count }}"
    purge_tags: False       <----- This is now needed everywhere tags are used to say "leave alone" ?
    region: eu-central-1

This is the ONLY case where one has to specify a non-default option just to say: "leave alone".

Note also that

    purge_tags: False 

is NOT backwards compatible, because that field didn't exist in previous versions, so you need 2 different cases depending on which side of this version you fall on.

Given that the purge_tags things seems to have propagated to many AWS assets, all in slightly different releases, one needs to account for this on a case by case basis depending on when the purge_tags was introduced into each module.

Now, if the default had been purge_tags=False, none of this would be an issue.
There would have been no changes required as the new behavior would match the old.

Am I the only one complaining about this? I can't believe this didn't hit more people.
Does no use use ansible to alter "only what is specified" and expect the rest to remain as-is?

I can't decide now whether to walk away from ansible as an AWS "minor edit" tool or, try deal with this "maybe we'll change something that destroys something else later, that you can't know about until it happens.

@jillr
Copy link
Collaborator

jillr commented Apr 13, 2022

Hi @bedge. I'm sorry to hear that this change caused unexpected behaviour in your environment, that's definitely not the experience we want users to have. purge_tags=True is the default in a majority of Ansible AWS modules that support tagging and we did communicate the new option in the changelog for the collection update. That doesn't mean that this setting is perfect or set in stone though - we would be happy to take a bug report in a new issue where we can discuss as a community if we chose the correct default here and if it should be changed.

The developers who work on this collection are human and while we try our best sometimes humans make mistakes, or we make decisions without the same context that someone else has. I can assure you that no one is setting out to "change something that destroys something else later, that you can't know about until it happens". We strive to communicate all changes in a release in the changelog, if there's something we could have done differently with that changelog entry we would also welcome that feedback in the bug report.

softwarefactory-project-zuul bot pushed a commit that referenced this pull request Apr 14, 2022
ec2_asg: Change purge_tags default value to False

SUMMARY

Changed default value of purge_tags to False.

With the addition of purge_tags to ec2_asg module #960, the default value was kept to True similar to many other modules in this collection and also as specified in ansible dev guide.
With this addition, the issue was discovered that there is a possibility of this change breaking existing playbooks for users if they don't update their playbooks and specify purge_tags: false where required.
This PR's change will prevent accidental breakage.
ISSUE TYPE


Bugfix Pull Request

COMPONENT NAME

ec2_asg

Reviewed-by: Mark Chappell <None>
Reviewed-by: Markus Bergholz <[email protected]>
Reviewed-by: Mark Woolley <[email protected]>
Reviewed-by: Alina Buzachis <None>
patchback bot pushed a commit that referenced this pull request Apr 14, 2022
ec2_asg: Change purge_tags default value to False

SUMMARY

Changed default value of purge_tags to False.

With the addition of purge_tags to ec2_asg module #960, the default value was kept to True similar to many other modules in this collection and also as specified in ansible dev guide.
With this addition, the issue was discovered that there is a possibility of this change breaking existing playbooks for users if they don't update their playbooks and specify purge_tags: false where required.
This PR's change will prevent accidental breakage.
ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME

ec2_asg

Reviewed-by: Mark Chappell <None>
Reviewed-by: Markus Bergholz <[email protected]>
Reviewed-by: Mark Woolley <[email protected]>
Reviewed-by: Alina Buzachis <None>
(cherry picked from commit d0c9f1a)
softwarefactory-project-zuul bot pushed a commit that referenced this pull request Apr 14, 2022
[PR #1064/d0c9f1a6 backport][stable-3] ec2_asg: Change purge_tags default value to False

This is a backport of PR #1064 as merged into main (d0c9f1a).
SUMMARY

Changed default value of purge_tags to False.

With the addition of purge_tags to ec2_asg module #960, the default value was kept to True similar to many other modules in this collection and also as specified in ansible dev guide.
With this addition, the issue was discovered that there is a possibility of this change breaking existing playbooks for users if they don't update their playbooks and specify purge_tags: false where required.
This PR's change will prevent accidental breakage.
ISSUE TYPE


Bugfix Pull Request

COMPONENT NAME

ec2_asg

Reviewed-by: Mark Chappell <None>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-3 PR should be backported to the stable-3 branch 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.

AutoScaling Group tags module
5 participants