From 146535f6ab9344a8d56809ff99f97bc6a3d598c3 Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Tue, 17 May 2022 15:32:10 +0200 Subject: [PATCH] ec2_transit_gateway_vpc_attachment - retry on IncorrectState (#1147) ec2_transit_gateway_vpc_attachment - retry on IncorrectState SUMMARY Follows on from #1110 - to retry ec2_transit_gateway_vpc_attachment failures Doing this separately because it's not in the stable-3 branch. ISSUE TYPE Bugfix Pull Request COMPONENT NAME ec2_transit_gateway_vpc_attachment ADDITIONAL INFORMATION Reviewed-by: Alina Buzachis This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/3347cb04867e3cfe545a2d2570ae5daf539e8441 --- plugins/module_utils/transitgateway.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/plugins/module_utils/transitgateway.py b/plugins/module_utils/transitgateway.py index e333be82e51..3ec198abdde 100644 --- a/plugins/module_utils/transitgateway.py +++ b/plugins/module_utils/transitgateway.py @@ -103,7 +103,23 @@ def _get_tgw_vpc_attachment(self, **params): return attachment -class TransitGatewayVpcAttachmentManager(TGWAttachmentBoto3Mixin, BaseEc2Manager): +class BaseTGWManager(BaseEc2Manager): + + @Boto3Mixin.aws_error_handler('connect to AWS') + def _create_client(self, client_name='ec2'): + if client_name == 'ec2': + error_codes = ['IncorrectState'] + else: + error_codes = [] + + retry_decorator = AWSRetry.jittered_backoff( + catch_extra_error_codes=error_codes, + ) + client = self.module.client(client_name, retry_decorator=retry_decorator) + return client + + +class TransitGatewayVpcAttachmentManager(TGWAttachmentBoto3Mixin, BaseTGWManager): TAG_RESOURCE_TYPE = 'transit-gateway-attachment'