cdk python transit gateway route table entry

500 views Asked by At

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?

1

There are 1 answers

0
bearrito On

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)