@digitraffic/common 2026.4.9-1 → 2026.4.15-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -6,7 +6,9 @@ import type { InfraStackConfiguration } from "./intra-stack-configuration.js";
|
|
|
6
6
|
export interface NetworkConfiguration {
|
|
7
7
|
readonly vpcName: string;
|
|
8
8
|
readonly cidr: string;
|
|
9
|
+
readonly transitGatewayId?: string;
|
|
9
10
|
}
|
|
11
|
+
/** Creates a network stack with VPC and optional transit gateway routing */
|
|
10
12
|
export declare class NetworkStack extends Stack {
|
|
11
13
|
readonly vpc: IVpc;
|
|
12
14
|
constructor(scope: Construct, id: string, isc: InfraStackConfiguration, configuration: NetworkConfiguration);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { IpAddresses, SubnetType, Vpc } from "aws-cdk-lib/aws-ec2";
|
|
1
|
+
import { CfnRoute, IpAddresses, SubnetType, Vpc } from "aws-cdk-lib/aws-ec2";
|
|
2
2
|
import { Stack } from "aws-cdk-lib/core";
|
|
3
3
|
import { exportValue } from "../import-util.js";
|
|
4
|
+
/** Creates a network stack with VPC and optional transit gateway routing */
|
|
4
5
|
export class NetworkStack extends Stack {
|
|
5
6
|
vpc;
|
|
6
7
|
constructor(scope, id, isc, configuration) {
|
|
@@ -21,12 +22,13 @@ export class NetworkStack extends Stack {
|
|
|
21
22
|
exportValue(this, isc.environmentName, "digitrafficprivateBSubnet", this.vpc.privateSubnets[1].subnetId);
|
|
22
23
|
}
|
|
23
24
|
createVpc(configuration) {
|
|
24
|
-
|
|
25
|
+
const vpc = new Vpc(this, "DigitrafficVPC", {
|
|
25
26
|
vpcName: configuration.vpcName,
|
|
26
27
|
restrictDefaultSecurityGroup: false,
|
|
27
28
|
availabilityZones: Stack.of(this).availabilityZones.sort().slice(0, 2), // take two first azs
|
|
28
29
|
enableDnsHostnames: true,
|
|
29
30
|
enableDnsSupport: true,
|
|
31
|
+
natGateways: configuration.transitGatewayId ? 0 : 2, // one for each AZ, or none if using transit gateway
|
|
30
32
|
ipAddresses: IpAddresses.cidr(configuration.cidr),
|
|
31
33
|
subnetConfiguration: [
|
|
32
34
|
{
|
|
@@ -41,6 +43,17 @@ export class NetworkStack extends Stack {
|
|
|
41
43
|
},
|
|
42
44
|
],
|
|
43
45
|
});
|
|
46
|
+
// route traffic to transit gateway
|
|
47
|
+
if (configuration.transitGatewayId) {
|
|
48
|
+
vpc.selectSubnets(undefined).subnets.forEach((subnet) => {
|
|
49
|
+
new CfnRoute(this, `SubnetRouteToTgw${subnet.node.id}`, {
|
|
50
|
+
routeTableId: subnet.routeTable.routeTableId,
|
|
51
|
+
destinationCidrBlock: "0.0.0.0/0",
|
|
52
|
+
transitGatewayId: configuration.transitGatewayId,
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
return vpc;
|
|
44
57
|
}
|
|
45
58
|
}
|
|
46
59
|
//# sourceMappingURL=network-stack.js.map
|