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: fix NoneType error (#695) #705

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 paginator for describe internet gateways and add retry to fix NoneType object is not subscriptable error (https://github.com/ansible-collections/amazon.aws/pull/695).
17 changes: 12 additions & 5 deletions plugins/modules/ec2_vpc_igw.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@
from ..module_utils.tagging import boto3_tag_list_to_ansible_dict


@AWSRetry.jittered_backoff(retries=10, delay=10)
def describe_igws_with_backoff(connection, **params):
paginator = connection.get_paginator('describe_internet_gateways')
return paginator.paginate(**params).build_full_result()['InternetGateways']


class AnsibleEc2Igw():

def __init__(self, module, results):
Expand All @@ -135,10 +141,8 @@ def process(self):

def get_matching_igw(self, vpc_id):
filters = ansible_dict_to_boto3_filter_list({'attachment.vpc-id': vpc_id})
igws = []
try:
response = self._connection.describe_internet_gateways(aws_retry=True, Filters=filters)
igws = response.get('InternetGateways', [])
igws = describe_igws_with_backoff(self._connection, Filters=filters)
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
self._module.fail_json_aws(e)

Expand Down Expand Up @@ -211,17 +215,20 @@ def ensure_igw_present(self, vpc_id, tags, purge_tags):
# Ensure the gateway is attached before proceeding
waiter = get_waiter(self._connection, 'internet_gateway_attached')
waiter.wait(InternetGatewayIds=[igw['internet_gateway_id']])

self._results['changed'] = True
except botocore.exceptions.WaiterError as e:
self._module.fail_json_aws(e, msg="No Internet Gateway exists.")
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
self._module.fail_json_aws(e, msg='Unable to create Internet Gateway')

# Modify tags
self._results['changed'] |= ensure_ec2_tags(
self._connection, self._module, igw['internet_gateway_id'],
resource_type='internet-gateway', tags=tags, purge_tags=purge_tags
resource_type='internet-gateway', tags=tags, purge_tags=purge_tags,
retry_codes='InvalidInternetGatewayID.NotFound'
)

# Update igw
igw = self.get_matching_igw(vpc_id)
igw_info = self.get_igw_info(igw, vpc_id)
self._results.update(igw_info)
Expand Down