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_vpc_igw - dont user filters to paginate to fix NoneType error #766

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- ec2_vpc_igw - use gateway_id rather than filters to paginate if possible to fix 'NoneType' object is not subscriptable error (https://github.com/ansible-collections/amazon.aws/pull/766).
19 changes: 16 additions & 3 deletions plugins/modules/ec2_vpc_igw.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,23 @@ def process(self):
elif state == 'absent':
self.ensure_igw_absent(vpc_id)

def get_matching_igw(self, vpc_id):
def get_matching_igw(self, vpc_id, gateway_id=None):
'''
Returns the internet gateway found.
Parameters:
vpc_id (str): VPC ID
gateway_id (str): Internet Gateway ID, if specified
Returns:
igw (dict): dict of igw found, None if none found
'''
filters = ansible_dict_to_boto3_filter_list({'attachment.vpc-id': vpc_id})
try:
igws = describe_igws_with_backoff(self._connection, Filters=filters)
# If we know the gateway_id, use it to avoid bugs with using filters
# See https://github.com/ansible-collections/amazon.aws/pull/766
if not gateway_id:
igws = describe_igws_with_backoff(self._connection, Filters=filters)
else:
igws = describe_igws_with_backoff(self._connection, InternetGatewayIds=[gateway_id])
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
self._module.fail_json_aws(e)

Expand Down Expand Up @@ -229,7 +242,7 @@ def ensure_igw_present(self, vpc_id, tags, purge_tags):
)

# Update igw
igw = self.get_matching_igw(vpc_id)
igw = self.get_matching_igw(vpc_id, gateway_id=igw['internet_gateway_id'])
igw_info = self.get_igw_info(igw, vpc_id)
self._results.update(igw_info)

Expand Down