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_group - fix VPC precedence for security group targets #45787

Merged
merged 1 commit into from
Sep 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions changelogs/fragments/fix_ec2_group_target_vpc_precedence.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
bugfixes:
- ec2_group - There can be multiple security groups with the same name in
different VPCs. Prior to 2.6 if a target group name was provided, the group
matching the name and VPC had highest precedence. Restore this behavior by
updated the dictionary with the groups matching the VPC last.
3 changes: 3 additions & 0 deletions lib/ansible/modules/cloud/amazon/ec2_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,9 @@ def group_exists(client, module, vpc_id, group_id, name):
if security_groups:
groups = dict((group['GroupId'], group) for group in all_groups)
groups.update(dict((group['GroupName'], group) for group in all_groups))
if vpc_id:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The VPC is used to filter above - but it doesn't only return results matching the VPC, it returns matches that meet at least one of the filters.

vpc_wins = dict((group['GroupName'], group) for group in all_groups if group['VpcId'] == vpc_id)
groups.update(vpc_wins)
# maintain backwards compatibility by using the last matching group
return security_groups[-1], groups
return None, {}
Expand Down