community.aws
community.aws copied to clipboard
KeyError: 'Description' when deleting transit gateway
Summary
I am trying to delete a transit gateway using the ec2_transit_gateway module and receiving a KeyError: 'Description'
when the task is executed.
I did find issue #68 that is similar to this and is closed. In this comment it was stated that the Description
key should always be returned, However, if the transit gateway is old enough (I don't know what the exact date of "old enough" is) then the Description
key is not returned.
As an example I have a transit gateway that was created on 2023-03-03 and there is no Description
key, but a transit gateway that was created today (2023-07-21) does have a Description
key. Using the AWS CLI (version 2.13.0) to get the information on the transit gateways shows this behavior:
aws ec2 describe-transit-gateways
{
"TransitGateways": [
{
"TransitGatewayId": <<REDACTED>>,
"TransitGatewayArn": <<REDACTED>>,
"State": "available",
"OwnerId": <<REDACTED>>,
"CreationTime": "2023-03-03T12:06:27+00:00",
....
},
{
"TransitGatewayId": <<REDACTED>>,
"TransitGatewayArn": <<REDACTED>>,
"State": "deleted",
"OwnerId": <<REDACTED>>,
"Description": "",
"CreationTime": "2023-07-21T22:19:56+00:00",
....
}
]
}
Issue Type
Bug Report
Component Name
ec2_transit_gateway
Ansible Version
$ ansible --version
ansible [core 2.14.6]
config file = /etc/ansible/ansible.cfg
configured module search path = ['/home/runner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.9/site-packages/ansible
ansible collection location = /home/runner/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.9.16 (main, May 31 2023, 12:21:58) [GCC 8.5.0 20210514 (Red Hat 8.5.0-18)] (/usr/bin/python3.9)
jinja version = 3.1.2
libyaml = True
Collection Versions
$ ansible-galaxy collection list
# /usr/share/ansible/collections/ansible_collections
Collection Version
------------- -------
amazon.aws 6.2.0
community.aws 6.1.0
AWS SDK versions
$ pip show boto boto3 botocore
WARNING: Package(s) not found: boto
Name: boto3
Version: 1.28.7
Summary: The AWS SDK for Python
Home-page: https://github.com/boto/boto3
Author: Amazon Web Services
Author-email:
License: Apache License 2.0
Location: /usr/local/lib/python3.9/site-packages
Requires: botocore, jmespath, s3transfer
Required-by:
---
Name: botocore
Version: 1.31.7
Summary: Low-level, data-driven core of boto 3.
Home-page: https://github.com/boto/botocore
Author: Amazon Web Services
Author-email:
License: Apache License 2.0
Location: /usr/local/lib/python3.9/site-packages
Requires: jmespath, python-dateutil, urllib3
Required-by: boto3, s3transfer
Configuration
$ ansible-config dump --only-changed
CONFIG_FILE() = /etc/ansible/ansible.cfg
OS / Environment
Red Hat Enterprise Linux release 8.8 (Ootpa)
Steps to Reproduce
In an AWS region create a transit gateway that does have a description (e.g. the description field is left blank in the AWS web UI) and then create a playbook with the below tasks (ensure to setup AWS authentication). If the region the transit gateway is created in is different than us-east-1
be sure to update the region in the tasks accordingly.
- name: Get EC2 transit gateway info
community.aws.ec2_transit_gateway_info:
region: us-east-1
register: __aws_ec2_vpcs_tgws
- name: Remove EC2 transit gateways
community.aws.ec2_transit_gateway:
transit_gateway_id: "{{ __aws_ec2_vpcs_tgws['transit_gateway_id'] }}"
region: us-east-1
state: absent
loop: "{{ __aws_ec2_vpcs_tgws['transit_gateways'] }}"
loop_control:
label: "Removing EC2 transit gateway {{ __aws_ec2_vpcs_tgws['transit_gateway_id'] }}
loop_var: __aws_ec2_vpcs_tgws
Expected Results
The transit gateway is deleted
Actual Results
The full traceback is:
Traceback (most recent call last):
File "/home/runner/.ansible/tmp/ansible-tmp-1689979849.497067-582-232165340950257/AnsiballZ_ec2_transit_gateway.py", line 107, in <module>
_ansiballz_main()
File "/home/runner/.ansible/tmp/ansible-tmp-1689979849.497067-582-232165340950257/AnsiballZ_ec2_transit_gateway.py", line 99, in _ansiballz_main
invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
File "/home/runner/.ansible/tmp/ansible-tmp-1689979849.497067-582-232165340950257/AnsiballZ_ec2_transit_gateway.py", line 47, in invoke_module
runpy.run_module(mod_name='ansible_collections.community.aws.plugins.modules.ec2_transit_gateway', init_globals=dict(_module_fqn='ansible_collections.community.aws.plugins.modules.ec2_transit_gateway', _modlib_path=modlib_path),
File "/usr/lib64/python3.9/runpy.py", line 225, in run_module
return _run_module_code(code, init_globals, run_name, mod_spec)
File "/usr/lib64/python3.9/runpy.py", line 97, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "/usr/lib64/python3.9/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/tmp/ansible_community.aws.ec2_transit_gateway_payload_gdim_pat/ansible_community.aws.ec2_transit_gateway_payload.zip/ansible_collections/community/aws/plugins/modules/ec2_transit_gateway.py", line 516, in <module>
File "/tmp/ansible_community.aws.ec2_transit_gateway_payload_gdim_pat/ansible_community.aws.ec2_transit_gateway_payload.zip/ansible_collections/community/aws/plugins/modules/ec2_transit_gateway.py", line 510, in main
File "/tmp/ansible_community.aws.ec2_transit_gateway_payload_gdim_pat/ansible_community.aws.ec2_transit_gateway_payload.zip/ansible_collections/community/aws/plugins/modules/ec2_transit_gateway.py", line 258, in process
File "/tmp/ansible_community.aws.ec2_transit_gateway_payload_gdim_pat/ansible_community.aws.ec2_transit_gateway_payload.zip/ansible_collections/community/aws/plugins/modules/ec2_transit_gateway.py", line 454, in ensure_tgw_absent
File "/tmp/ansible_community.aws.ec2_transit_gateway_payload_gdim_pat/ansible_community.aws.ec2_transit_gateway_payload.zip/ansible_collections/community/aws/plugins/modules/ec2_transit_gateway.py", line 325, in get_matching_tgw
KeyError: 'Description'
Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct