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' object is not subscriptable (#691) #697

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
2 changes: 2 additions & 0 deletions changelogs/fragments/691-ec2_vpc_igw-fix-null-igw-error.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- ec2_vpc_igw - fix 'NoneType' object is not subscriptable error (https://github.com/ansible-collections/amazon.aws/pull/691).
24 changes: 24 additions & 0 deletions plugins/module_utils/waiters.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,24 @@
},
]
},
"InternetGatewayAttached": {
"operation": "DescribeInternetGateways",
"delay": 5,
"maxAttempts": 40,
"acceptors": [
{
"expected": "available",
"matcher": "pathAll",
"state": "success",
"argument": "InternetGateways[].Attachments[].State"
},
{
"matcher": "error",
"expected": "InvalidInternetGatewayID.NotFound",
"state": "retry"
},
]
},
"NetworkInterfaceAttached": {
"operation": "DescribeNetworkInterfaces",
"delay": 5,
Expand Down Expand Up @@ -716,6 +734,12 @@ def route53_model(name):
core_waiter.NormalizedOperationMethod(
ec2.describe_internet_gateways
)),
('EC2', 'internet_gateway_attached'): lambda ec2: core_waiter.Waiter(
'internet_gateway_attached',
ec2_model('InternetGatewayAttached'),
core_waiter.NormalizedOperationMethod(
ec2.describe_internet_gateways
)),
('EC2', 'network_interface_attached'): lambda ec2: core_waiter.Waiter(
'network_interface_attached',
ec2_model('NetworkInterfaceAttached'),
Expand Down
5 changes: 5 additions & 0 deletions plugins/modules/ec2_vpc_igw.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,11 @@ def ensure_igw_present(self, vpc_id, tags, purge_tags):
InternetGatewayId=igw['internet_gateway_id'],
VpcId=vpc_id
)

# 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.")
Expand Down