From 881c03b9cfbe51bf4f32d8e3ac87c00a1ede427d Mon Sep 17 00:00:00 2001 From: Bharat Parmar Date: Wed, 3 Dec 2025 16:47:26 +0530 Subject: [PATCH] fix: (when routeTableStringFormat is true): uses -or-sanitized-cidr-Route, consistent with SubnetStack and honoring route.routeName if provided. --- API.md | 11 +++++++++++ CHANGELOG.md | 0 README.md | 4 ++++ src/constructs/network.ts | 26 ++++++++++++++++---------- 4 files changed, 31 insertions(+), 10 deletions(-) create mode 100644 CHANGELOG.md diff --git a/API.md b/API.md index 4d70b6f..f0db2be 100644 --- a/API.md +++ b/API.md @@ -2196,6 +2196,7 @@ public readonly routeTableId: string; | egressNetworkACL | NetworkACL[] | *No description.* | | ingressNetworkACL | NetworkACL[] | *No description.* | | routes | AddRouteOptions[] | *No description.* | +| routeTableStringFormat | boolean | *No description.* | | tags | {[ key: string ]: string} | *No description.* | | useNestedStacks | boolean | *No description.* | | useSubnetForNAT | boolean | *No description.* | @@ -2272,6 +2273,16 @@ public readonly routes: AddRouteOptions[]; --- +##### `routeTableStringFormat`Optional + +```typescript +public readonly routeTableStringFormat: boolean; +``` + +- *Type:* boolean + +--- + ##### `tags`Optional ```typescript diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..e69de29 diff --git a/README.md b/README.md index 740c776..f11d824 100644 --- a/README.md +++ b/README.md @@ -293,3 +293,7 @@ Here’s a breakdown of the configuration options available: 4. externalSubnets: Specify external subnets if you need to define subnets manually (each with an id, availabilityZone, and routeTableId). 5. iamPolicyStatements: (Optional) Attach IAM policy statements to control access to the endpoint. 6. additionalTags: (Optional) Add custom tags to the VPC Endpoint for easier identification and tracking. + + + +- :white_check_mark: Configurable route table entry naming for subnet routes via `routeTableStringFormat` \ No newline at end of file diff --git a/src/constructs/network.ts b/src/constructs/network.ts index 3fc0313..ee41cb7 100644 --- a/src/constructs/network.ts +++ b/src/constructs/network.ts @@ -60,6 +60,7 @@ export interface ISubnetsProps { readonly ingressNetworkACL?: NetworkACL[]; readonly egressNetworkACL?: NetworkACL[]; readonly routes?: AddRouteOptions[]; + readonly routeTableStringFormat?: boolean; readonly tags?: Record; readonly useSubnetForNAT?: boolean; readonly useNestedStacks?: boolean; @@ -267,11 +268,18 @@ export class Network extends Construct { }, ); option.routes?.forEach((route, routeIndex) => { + const useNewFormat = option.routeTableStringFormat ?? false; + const destinationKey = + route.routeName ?? route.destinationCidrBlock?.replace(/[./]/g, '-'); + + const routeTableName = + useNewFormat && destinationKey + ? `${option.subnetGroupName}-${destinationKey}-Route` + : `${option.subnetGroupName}${routeIndex}RouteEntry`; if (peeringConnectionId != undefined && route.existingVpcPeeringRouteKey != undefined) { let routeId: ec2.CfnVPCPeeringConnection | undefined = peeringConnectionId[route.existingVpcPeeringRouteKey]; if (routeId != undefined) { - subnet.addRoute( - `${option.subnetGroupName}${routeIndex}RouteEntry`, + subnet.addRoute(routeTableName, { routerId: routeId.ref, routerType: route.routerType, @@ -280,14 +288,12 @@ export class Network extends Construct { ); } } else if (route.routerId != undefined) { - subnet.addRoute( - `${option.subnetGroupName}${routeIndex}RouteEntry`, - { - routerId: route.routerId ?? '', - routerType: route.routerType, - destinationCidrBlock: route.destinationCidrBlock, - }, - ); + // Check the value of option.routeTableStringFormat to format the route name accordingly + subnet.addRoute(routeTableName, { + routerId: route.routerId ?? '', + routerType: route.routerType, + destinationCidrBlock: route.destinationCidrBlock, + }); } });