ec2_vpc_route_table: Update matching_count parsing on find_subnets fu… (#38707)

* ec2_vpc_route_table: Update matching_count parsing on find_subnets function and tests

* ec2_vpc_route_table: Update matching_count parsing on find_subnets function
This commit is contained in:
Julien PRIGENT 2018-05-03 20:05:24 +01:00 committed by Ryan Brown
commit 1905a6e8fb
2 changed files with 75 additions and 3 deletions

View file

@ -256,7 +256,7 @@ def find_subnets(connection, module, vpc_id, identified_subnets):
'Name' tag, or a CIDR such as 10.0.0.0/8.
Note that this function is duplicated in other ec2 modules, and should
potentially be moved into potentially be moved into a shared module_utils
potentially be moved into a shared module_utils
"""
subnet_ids = []
subnet_names = []
@ -294,7 +294,7 @@ def find_subnets(connection, module, vpc_id, identified_subnets):
module.fail_json_aws(e, msg="Couldn't find subnet with names %s" % subnet_names)
for name in subnet_names:
matching_count = len([1 for s in subnets_by_name if s.tags.get('Name') == name])
matching_count = len([1 for s in subnets_by_name for t in s.get('Tags', []) if t['Key'] == 'Name' and t['Value'] == name])
if matching_count == 0:
module.fail_json(msg='Subnet named "{0}" does not exist'.format(name))
elif matching_count > 1: