Skip to content

Commit

Permalink
ec2_group - fix VPC precedence for security group targets (ansible#45787
Browse files Browse the repository at this point in the history
)

Update the dictionary with the preferred values last to get the right order of VPC precedence

Fixes ansible#45782
  • Loading branch information
s-hertel authored and ryansb committed Sep 18, 2018
1 parent 06e2e0e commit 8d2df9b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
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:
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

0 comments on commit 8d2df9b

Please sign in to comment.