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)

ec2_vpc_igw: fix 'NoneType' object is not subscriptable

Depends-On: ansible/ansible-zuul-jobs#1368
SUMMARY
Add "InternetGatewayAttached" waiter
Fixes ansible-collections#647
ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME
ec2_vpc_igw

Reviewed-by: Alina Buzachis <None>
Reviewed-by: Joseph Torcasso <None>
Reviewed-by: Jill R <None>
Reviewed-by: Abhijeet Kasurde <None>
  • Loading branch information
jatorcasso committed Mar 1, 2022
1 parent 106a137 commit 7850962
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 @@ -55,6 +55,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 @@ -753,6 +771,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 7850962

Please sign in to comment.