From 72378dcee17a0e437af7d626e3a1263d01b9edd8 Mon Sep 17 00:00:00 2001 From: Alina Buzachis Date: Fri, 11 Mar 2022 18:55:19 +0100 Subject: [PATCH] ec2_vpc_igw: fix 'NoneType' object is not subscriptable (#691) (#697) ec2_vpc_igw: fix 'NoneType' object is not subscriptable (#691) Manual backport to stable-3: ec2_vpc_igw: fix 'NoneType' object is not subscriptable 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 8cc9397) SUMMARY ISSUE TYPE Bugfix Pull Request Docs Pull Request Feature Pull Request New Module Pull Request COMPONENT NAME ADDITIONAL INFORMATION --- .../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 c0fb1cdc4ed..20aaf9696ca 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.")