Skip to content

Commit

Permalink
update code to use updated module_utils/ec2 describe_transit_gateways
Browse files Browse the repository at this point in the history
  • Loading branch information
mandar242 committed Oct 16, 2024
1 parent 129a8b4 commit 809b64a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
22 changes: 11 additions & 11 deletions plugins/modules/ec2_transit_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
version_added: 8.1.0
state:
description:
- C(present) to ensure resource is created.
- C(absent) to remove resource.
- V(present) to ensure resource is created.
- V(absent) to remove resource.
default: present
choices: [ "present", "absent"]
type: str
Expand All @@ -57,11 +57,11 @@
default: true
type: bool
wait:
description: Whether to wait for status
description: Whether to wait for status.
default: true
type: bool
wait_timeout:
description: number of seconds to wait for status
description: Number of seconds to wait for status.
default: 300
type: int
Expand Down Expand Up @@ -128,7 +128,7 @@
type: str
sample: "my test tgw"
options:
description: The options attributes of the transit gateway
description: The options attributes of the transit gateway.
returned: always
type: complex
contains:
Expand Down Expand Up @@ -195,7 +195,7 @@
type: str
sample: "pending"
tags:
description: A dictionary of resource tags
description: A dictionary of resource tags.
returned: always
type: dict
sample:
Expand Down Expand Up @@ -240,7 +240,7 @@ def __init__(self, module: Any, results: Dict[str, Any]) -> None:
retry_decorator = AWSRetry.jittered_backoff(
catch_extra_error_codes=["IncorrectState"],
)
self._connection = module.client("ec2", retry_decorator=retry_decorator)
self._connection = module.client("ec2")
self._check_mode = self._module.check_mode

def process(self) -> None:
Expand Down Expand Up @@ -313,11 +313,11 @@ def get_matching_tgw(
tgw = None
tgws = []

if len(response.get("TransitGateways", [])) == 1 and tgw_id:
if (response["TransitGateways"][0]["State"] != "deleted") or not skip_deleted:
tgws.extend(response["TransitGateways"])
if len(response) == 1 and tgw_id:
if (response[0]["State"] != "deleted") or not skip_deleted:
tgws.extend(response)

for gateway in response.get("TransitGateways", []):
for gateway in response:
if description == gateway["Description"] and gateway["State"] != "deleted":
tgws.append(gateway)

Expand Down
7 changes: 2 additions & 5 deletions plugins/modules/ec2_transit_gateway_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,8 @@ def get_transit_gateway_response(module: AnsibleAWSModule, connection) -> Dict[s
if filters:
params["Filters"] = filters

try:
result = describe_ec2_transit_gateways(connection, **params)
return result if result else {"TransitGateways": []}
except AnsibleEC2Error as e:
module.fail_json_aws(e)
result = describe_ec2_transit_gateways(connection, **params)
return result if result else {"TransitGateways": []}


def extract_transit_gateway_info(transit_gateway: Dict[str, Any]) -> Dict[str, Any]:
Expand Down

0 comments on commit 809b64a

Please sign in to comment.