Skip to content

Commit

Permalink
ec2_vpc_igw: fix 'NoneType' object is not subscriptable (ansible-coll…
Browse files Browse the repository at this point in the history
…ections#691) (ansible-collections#698)

ec2_vpc_igw: fix 'NoneType' object is not subscriptable (ansible-collections#691)

Manual backport to stable-2: ec2_vpc_igw: fix 'NoneType' object is not subscriptable
SUMMARY
Add "InternetGatewayAttached" waiter
Fixes ansible-collections#647
ISSUE TYPE
Bugfix Pull Request
COMPONENT NAME
ec2_vpc_igw
Reviewed-by: Alina Buzachis 
Reviewed-by: Joseph Torcasso 
Reviewed-by: Jill R 
Reviewed-by: Abhijeet Kasurde 
(cherry picked from commit 8cc9397)
SUMMARY


ISSUE TYPE


Bugfix Pull Request
Docs Pull Request
Feature Pull Request
New Module Pull Request

COMPONENT NAME

ADDITIONAL INFORMATION
  • Loading branch information
alinabuzachis authored Mar 11, 2022
1 parent 5bc5599 commit 787bb74
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
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

0 comments on commit 787bb74

Please sign in to comment.