From 6db042dc72eaf86b35f337d184cb63feb5055fa4 Mon Sep 17 00:00:00 2001 From: Mohit Alonja Date: Tue, 10 Aug 2021 11:41:50 +0530 Subject: [PATCH] Added DisassociateTransitGatewayRouteTable API (#4154) --- moto/ec2/models.py | 23 ++++++++++++++++++ .../responses/transit_gateway_attachments.py | 24 +++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/moto/ec2/models.py b/moto/ec2/models.py index 6008ed24c..08bf22da9 100644 --- a/moto/ec2/models.py +++ b/moto/ec2/models.py @@ -6240,6 +6240,10 @@ class TransitGatewayRouteTableBackend(object): "transitGatewayAttachmentId": transit_gateway_attachment_id, } + def unset_route_table_association(self, tgw_rt_id): + tgw_rt = self.transit_gateways_route_tables[tgw_rt_id] + tgw_rt.route_table_association = {} + def set_route_table_propagation( self, transit_gateway_attachment_id, transit_gateway_route_table_id ): @@ -6256,6 +6260,10 @@ class TransitGatewayRouteTableBackend(object): "transitGatewayAttachmentId": transit_gateway_attachment_id, } + def unset_route_table_propagation(self, tgw_rt_id): + tgw_rt = self.transit_gateways_route_tables[tgw_rt_id] + tgw_rt.route_table_propagation = {} + def disable_route_table_propagation(self, transit_gateway_route_table_id): self.transit_gateways_route_tables[ transit_gateway_route_table_id @@ -6538,6 +6546,9 @@ class TransitGatewayAttachmentBackend(object): "transitGatewayRouteTableId": transit_gateway_route_table_id, } + def unset_attachment_association(self, tgw_attach_id): + self.transit_gateway_attachments.get(tgw_attach_id).association = {} + def set_attachment_propagation( self, transit_gateway_attachment_id=None, transit_gateway_route_table_id=None ): @@ -6546,6 +6557,9 @@ class TransitGatewayAttachmentBackend(object): "transitGatewayRouteTableId": transit_gateway_route_table_id, } + def unset_attachment_propagation(self, tgw_attach_id): + self.transit_gateway_attachments.get(tgw_attach_id).propagation = {} + def disable_attachment_propagation(self, transit_gateway_attachment_id=None): self.transit_gateway_attachments[transit_gateway_attachment_id].propagation[ "state" @@ -6715,6 +6729,15 @@ class TransitGatewayRelationsBackend(object): return transit_gateway_propagation + def disassociate_transit_gateway_route_table(self, tgw_attach_id, tgw_rt_id): + tgw_association = self.transit_gateway_associations.pop(tgw_attach_id) + tgw_association.state == "disassociated" + + self.unset_route_table_association(tgw_rt_id) + self.unset_attachment_association(tgw_attach_id) + + return tgw_association + class NatGateway(CloudFormationModel): def __init__(self, backend, subnet_id, allocation_id, tags=[]): diff --git a/moto/ec2/responses/transit_gateway_attachments.py b/moto/ec2/responses/transit_gateway_attachments.py index 0b877c8c9..4edef0617 100644 --- a/moto/ec2/responses/transit_gateway_attachments.py +++ b/moto/ec2/responses/transit_gateway_attachments.py @@ -88,6 +88,17 @@ class TransitGatewayAttachment(BaseResponse): template = self.response_template(TRANSIT_GATEWAY_ASSOCIATION) return template.render(transit_gateway_association=transit_gateway_association) + def disassociate_transit_gateway_route_table(self,): + tgw_attach_id = self._get_param("TransitGatewayAttachmentId") + tgw_rt_id = self._get_param("TransitGatewayRouteTableId") + + tgw_association = self.ec2_backend.disassociate_transit_gateway_route_table( + tgw_attach_id, tgw_rt_id + ) + tgw_association.state == "disassociated" + template = self.response_template(TRANSIT_GATEWAY_DISASSOCIATION) + return template.render(tgw_association=tgw_association) + def enable_transit_gateway_route_table_propagation(self): transit_gateway_attachment_id = self._get_param("TransitGatewayAttachmentId") transit_gateway_route_table_id = self._get_param("TransitGatewayRouteTableId") @@ -351,6 +362,19 @@ TRANSIT_GATEWAY_ASSOCIATION = """ + 86a597cf-93ec-44a3-9559-4641863642a5 + + {{ tgw_association.resource_id }} + {{ tgw_association.resource_type }} + {{ tgw_association.state }} + {{ tgw_association.transit_gateway_attachment_id }} + {{ tgw_association.transit_gateway_route_table_id }} + + +""" + + TRANSIT_GATEWAY_PROPAGATION = """ c78427d4-e498-46ae-bc14-32841b16bff4