From 8ddf38bc4e609d34ffc8c03aa87d59636ffe5e9d Mon Sep 17 00:00:00 2001 From: "vardy.ng" Date: Wed, 11 Dec 2024 16:31:51 -0500 Subject: [PATCH] implement hasRouteToCloudWAN function --- packages/aws-cdk/lib/context-providers/vpcs.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/aws-cdk/lib/context-providers/vpcs.ts b/packages/aws-cdk/lib/context-providers/vpcs.ts index 0ad6a277ad574..7f68ce57b54c4 100644 --- a/packages/aws-cdk/lib/context-providers/vpcs.ts +++ b/packages/aws-cdk/lib/context-providers/vpcs.ts @@ -234,11 +234,24 @@ class RouteTables { ); } + + /** + * Whether the given subnet has a route to a CloudWAN Network + */ + public hasRouteToCloudWAN(subnetId: string | undefined): boolean { + const table = this.tableForSubnet(subnetId) || this.mainRouteTable; + + return ( + !!table && !!table.Routes && table.Routes.some((route) => !!route.CoreNetworkArn && route.DestinationCidrBlock === '0.0.0.0/0') + ); + } + public tableForSubnet(subnetId: string | undefined) { return this.tables.find( (table) => !!table.Associations && table.Associations.some((assoc) => assoc.SubnetId === subnetId), ); } + } /**