'cdk python transit gateway route table entry

Using cdk I'm trying to make a route table entry. The target I'm trying to add is a transit gateway. I'm using the Subnet construct and the add_route() method.

https://docs.aws.amazon.com/cdk/api/latest/python/aws_cdk.aws_ec2/Subnet.html

There is a mandatory parameter to add_route() called router_type (of type RouterType).

https://docs.aws.amazon.com/cdk/api/latest/python/aws_cdk.aws_ec2/RouterType.html#aws_cdk.aws_ec2.RouterType

Problem is there doesn't seem to be one for transit gateways! How do I make a route table entry for transit gateways?



Solution 1:[1]

The following worked for me

tgw = ec2.CfnTransitGateway(....)

subnets = your_vpc.select_subnets(
            subnet_group_name="whatever here",
        ).subnets

for subnet in subnets:
    ec2.CfnRoute(
                self,
                subnet.node.addr + "TGW",
                route_table_id=subnet.route_table.route_table_id,
                transit_gateway_id=tgw.attr_id,
                destination_cidr_block="your cidr here.",
            ).add_depends_on(tgw)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 bearrito