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 ec2_asg_tag module #482

Closed
wants to merge 1 commit into from
Closed

Conversation

jsok
Copy link

@jsok jsok commented Mar 17, 2021

SUMMARY

A new module to manage ASG tags, analogous to the ec2_tag module in
amazon.aws collection.

Fixes #481

ISSUE TYPE
  • New Module Pull Request
COMPONENT NAME

ec2_asg_tag

ADDITIONAL INFORMATION

Motivation is outlined in #481, but this module provides a more declarative approach to managing ASG tags, e.g.:

- name: Ensure tags are present on an ASG
  community.aws.ec2_asg_tag:
    resource: my-auto-scaling-group
    state: present
    tags:
      - environment: production
        propagate_at_launch: true
      - role: webserver
        propagate_at_launch: true

- name: Ensure tag is absent on an ASG
  community.aws.ec2_asg_tag:
    resource: my-auto-scaling-group
    state: absent
    tags:
      - environment: development

The module utilises underlying API calls to:

@ansibullbot
Copy link

@ansibullbot ansibullbot added community_review integration tests/integration module module needs_triage new_contributor Help guide this first time contributor new_module New module new_plugin New plugin plugins plugin (any type) tests tests labels Mar 17, 2021
@jsok
Copy link
Author

jsok commented Mar 17, 2021

ansible/check failure seems to be unrelated to the change.

plugins/modules/ec2_asg_tag.py Outdated Show resolved Hide resolved
@markuman
Copy link
Member

recheck

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.

LGTM
dunno if you get the 1.4.0 train. maybe it is to late.

plugins/modules/ec2_asg_tag.py Show resolved Hide resolved
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.

Oh, you need also a changelog fragment.

@ansibullbot ansibullbot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR and removed community_review labels Mar 18, 2021
@jsok
Copy link
Author

jsok commented Mar 19, 2021

Oh, you need also a changelog fragment.

Can you please advise what a new module fragment looks like? I've been unable to find any such occurrence in the git log.

@jsok jsok force-pushed the asg-tag branch 2 times, most recently from 9619414 to 03c7023 Compare March 19, 2021 06:04
@jsok
Copy link
Author

jsok commented Mar 19, 2021

ready_for_review

@ansibullbot ansibullbot added community_review and removed needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR labels Mar 19, 2021
A new module to manage ASG tags, analogous to the `ec2_tag` module in
`amazon.aws` collection.

Fixes ansible-collections#481
@markuman
Copy link
Member

Oh, you need also a changelog fragment.

Can you please advise what a new module fragment looks like? I've been unable to find any such occurrence in the git log.

Take a look in the changelogs/fragments/ folder.
https://docs.ansible.com/ansible/latest/community/development_process.html#changelogs
So you'll need a minor_changes fragment for a new module.

@ansibullbot ansibullbot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR and removed community_review labels Mar 19, 2021
@jsok
Copy link
Author

jsok commented Mar 19, 2021

So you'll need a minor_changes fragment for a new module.

Reading that document suggests otherwise:

You do not have to add a changelog fragment for PRs that add new modules and plugins, because our tooling does that for you automatically.

@jsok
Copy link
Author

jsok commented Mar 19, 2021

recheck

@jsok
Copy link
Author

jsok commented Mar 19, 2021

/rebuild_failed

@jsok
Copy link
Author

jsok commented Mar 22, 2021

/rebuild

@jsok
Copy link
Author

jsok commented Mar 25, 2021

@markuman can I please get another review on this? The Shippable check if failing for unrelated reasons to this PR/change.

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.

Thanks for this PR @jsok. We just recently migrated off of Shippable CI and onto Zuul (the ansible/check Checks) and it looks like this PR just got caught in that transition time, no need to worry about those failures.

return tag_list


def compare_asg_tags(current_tags_dict, new_tags_dict, purge_tags=True):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you please import and use the compare_aws_tags function from the module utility?
https://github.com/ansible-collections/amazon.aws/blob/main/plugins/module_utils/ec2.py#L783

Copy link
Author

Choose a reason for hiding this comment

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

@jillr this and the other requested changes weren't possible based on my testing.

ASG tags aren't just K/V pairs (as expected by compare_aws_tags, boto3_tag_list_to_ansible_dict and ansible_dict_to_boto3_tag_list), they're a list of dicts instead. The ramification here is that if propagate_at_launch is changed but the K/V doesn't, the module won't detect any tag changes which I believe is not the desired behaviour.

Another issue I ran into was that the to_text and to_native functions did some odd things, particularly around None values. Hence why compare_asg_tags doesn't use them like compare_aws_tags.
From memory you can't roundtrip None like to_native(to_text(None))... or maybe it was the other way around? 🤔

return tags_to_set, tag_keys_to_unset


def tag_list_to_dict(tag_list):
Copy link
Collaborator

Choose a reason for hiding this comment

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

from ansible_collections.amazon.aws.plugins.module_utils.ec2 import AWSRetry


def to_boto3_tag_list(tags, group_name):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you please import and use the ansible_dict_to_boto3_tag_list function from the module utility?

@@ -247,6 +247,124 @@
- "output.tags | length == 1"
- output is changed

# ============================================================

Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you please add some tests for adding and removing tags in check_mode?

@jsok
Copy link
Author

jsok commented Apr 19, 2021

Hi all, thanks for the reviews but unfortunately I won't have time to follow up on the requested changes (this PR was to help implement something at my previous role, however I've moved roles since raising the PR).

I'm going to close this PR but happy for someone else to pick up where I left off. Sorry for the inconvenience ❤️

@jsok jsok closed this Apr 19, 2021
@jsok jsok deleted the asg-tag branch April 19, 2021 23:05
softwarefactory-project-zuul bot pushed a commit that referenced this pull request Mar 11, 2022
ec2_asg: Add purge_tags to AutoScalingGroups.

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

Reviewed-by: Alina Buzachis <None>
Reviewed-by: Jill R <None>
Reviewed-by: Mandar Kulkarni <[email protected]>
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]>
alinabuzachis pushed a commit to alinabuzachis/community.aws that referenced this pull request May 25, 2022
…#483)

ec2_vol: Fix incorrectly returned changed result

SUMMARY
When modify_volume is used but no new disk is being attached, the module incorrectly reports that no change has occurred even when disks have been modified (iops, throughput, type, etc.). This is due to the attach function overwriting the changed variable even if no disks are attached.
Fixes ansible-collections#482
The integration test has been fixed so that when the gp3 modifications are tested, the volume is already in an attached state (previously detached) when reporting back changed. The detach tests are moved further down now, allowing this case to be properly covered by the existing assert:

  
    
      amazon.aws/tests/integration/targets/ec2_vol/tasks/tests.yml
    
    
        Lines 384 to 387
      in
      e8df917
    
    
    
    

        
          
           - name: check that volume_type has changed 
        

        
          
             assert: 
        

        
          
               that: 
        

        
          
                 - changed_gp3_volume.changed 
        
    
  


ISSUE TYPE


Bugfix Pull Request

COMPONENT NAME
ec2_vol

Reviewed-by: Alina Buzachis <None>
Reviewed-by: None <None>
Reviewed-by: Mark Chappell <None>
Reviewed-by: None <None>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integration tests/integration module module needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR needs_triage new_contributor Help guide this first time contributor new_module New module new_plugin New plugin plugins plugin (any type) tests tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AutoScaling Group tags module
4 participants