From 8bde18f8c186bf47689709f8a249ba75a5189129 Mon Sep 17 00:00:00 2001 From: Joseph Torcasso <87090265+jatorcasso@users.noreply.github.com> Date: Mon, 28 Feb 2022 22:37:41 -0500 Subject: [PATCH] ec2_vpc_igw: fix 'NoneType' object is not subscriptable (#691) ec2_vpc_igw: fix 'NoneType' object is not subscriptable Depends-On: ansible/ansible-zuul-jobs#1368 SUMMARY Add "InternetGatewayAttached" waiter Fixes #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 8cc9397fb931057f93ab36b0f06b7cf218891a68) --- .../691-ec2_vpc_igw-fix-null-igw-error.yml | 2 ++ plugins/module_utils/waiters.py | 24 +++++++++++++++++++ plugins/modules/ec2_vpc_igw.py | 5 ++++ 3 files changed, 31 insertions(+) create mode 100644 changelogs/fragments/691-ec2_vpc_igw-fix-null-igw-error.yml diff --git a/changelogs/fragments/691-ec2_vpc_igw-fix-null-igw-error.yml b/changelogs/fragments/691-ec2_vpc_igw-fix-null-igw-error.yml new file mode 100644 index 00000000000..eaede040773 --- /dev/null +++ b/changelogs/fragments/691-ec2_vpc_igw-fix-null-igw-error.yml @@ -0,0 +1,2 @@ +bugfixes: + - ec2_vpc_igw - fix 'NoneType' object is not subscriptable error (https://github.com/ansible-collections/amazon.aws/pull/691). \ No newline at end of file diff --git a/plugins/module_utils/waiters.py b/plugins/module_utils/waiters.py index 403fdb3a023..40eb8c47381 100644 --- a/plugins/module_utils/waiters.py +++ b/plugins/module_utils/waiters.py @@ -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, @@ -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'), diff --git a/plugins/modules/ec2_vpc_igw.py b/plugins/modules/ec2_vpc_igw.py index 84fd6169065..b8308b5519e 100644 --- a/plugins/modules/ec2_vpc_igw.py +++ b/plugins/modules/ec2_vpc_igw.py @@ -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.")