diff --git a/plugins/module_utils/ec2.py b/plugins/module_utils/ec2.py index 26b15ea6ea1..2a6b9453ab3 100644 --- a/plugins/module_utils/ec2.py +++ b/plugins/module_utils/ec2.py @@ -1537,3 +1537,37 @@ def normalize_ec2_vpc_dhcp_config(option_config: List[Dict[str, Any]]) -> Dict[s config_data[option] = [val["Value"] for val in config_item["Values"]] return config_data + + +# EC2 Transit Gateway +class EC2TransitGatewayErrorHandler(AWSErrorHandler): + _CUSTOM_EXCEPTION = AnsibleEC2Error + + @classmethod + def _is_missing(cls): + return is_boto3_error_code("InvalidTransitGatewayID.NotFound") + + +@EC2TransitGatewayErrorHandler.list_error_handler("describe transit gateway", []) +@AWSRetry.jittered_backoff() +def describe_ec2_transit_gateways( + client, **params: Dict[str, Union[List[str], List[Dict[str, Union[str, List[str]]]]]] +) -> List[Dict[str, Any]]: + paginator = client.get_paginator("describe_transit_gateways") + return paginator.paginate(**params).build_full_result() + + +@EC2TransitGatewayErrorHandler.common_error_handler("create transit gateway") +@AWSRetry.jittered_backoff() +def create_ec2_transit_gateway( + client, **params: Dict[str, Union[List[str], List[Dict[str, Union[str, List[str]]]]]] +) -> List[Dict[str, Any]]: + return client.create_transit_gateway(**params) + + +@EC2TransitGatewayErrorHandler.deletion_error_handler("delete transit gateway") +@AWSRetry.jittered_backoff() +def delete_ec2_transit_gateway( + client, **params: Dict[str, Union[List[str], List[Dict[str, Union[str, List[str]]]]]] +) -> List[Dict[str, Any]]: + return client.delete_transit_gateway(**params)