Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeyError: 'Description' when deleting transit gateway #2368

Closed
1 task done
branic opened this issue Jul 21, 2023 · 2 comments · Fixed by #2375
Closed
1 task done

KeyError: 'Description' when deleting transit gateway #2368

branic opened this issue Jul 21, 2023 · 2 comments · Fixed by #2375
Labels
bug This issue/PR relates to a bug module module plugins plugin (any type) python3 traceback

Comments

@branic
Copy link
Contributor

branic commented Jul 21, 2023

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 ansible-collections/community.aws#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

  • I agree to follow the Ansible Code of Conduct
@ansibullbot
Copy link

Files identified in the description:

If these files are inaccurate, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibullbot
Copy link

@ansibullbot ansibullbot added bug This issue/PR relates to a bug module module needs_triage plugins plugin (any type) python3 traceback labels Jul 21, 2023
@alinabuzachis alinabuzachis transferred this issue from ansible-collections/community.aws Oct 28, 2024
softwarefactory-project-zuul bot pushed a commit that referenced this issue Nov 11, 2024
SUMMARY

When one or more TGWs exist with an empty description, the module will fail.
Fixes #2368

ISSUE TYPE


Bugfix Pull Request

COMPONENT NAME

ec2_transit_gateway
ADDITIONAL INFORMATION


Apparently, ansible-collections/community.aws#2086 failed to merge, and the ec2_transit_gateway module has now been migrated to amazon.aws. This PR just cherry-picks the commits on top of this repo.

Reviewed-by: Alina Buzachis
Reviewed-by: GomathiselviS <[email protected]>
patchback bot pushed a commit that referenced this issue Nov 11, 2024
SUMMARY

When one or more TGWs exist with an empty description, the module will fail.
Fixes #2368

ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME

ec2_transit_gateway
ADDITIONAL INFORMATION

Apparently, ansible-collections/community.aws#2086 failed to merge, and the ec2_transit_gateway module has now been migrated to amazon.aws. This PR just cherry-picks the commits on top of this repo.

Reviewed-by: Alina Buzachis
Reviewed-by: GomathiselviS <[email protected]>
(cherry picked from commit 69d81d5)
softwarefactory-project-zuul bot pushed a commit that referenced this issue Nov 11, 2024
This is a backport of PR #2375 as merged into main (69d81d5).
SUMMARY

When one or more TGWs exist with an empty description, the module will fail.
Fixes #2368

ISSUE TYPE


Bugfix Pull Request

COMPONENT NAME

ec2_transit_gateway
ADDITIONAL INFORMATION


Apparently, ansible-collections/community.aws#2086 failed to merge, and the ec2_transit_gateway module has now been migrated to amazon.aws. This PR just cherry-picks the commits on top of this repo.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue/PR relates to a bug module module plugins plugin (any type) python3 traceback
Projects
None yet
3 participants