import { Vpc } from "@fjall/components-infrastructure/lib/resources/aws/networking/vpc";
import * as ec2 from "aws-cdk-lib/aws-ec2";
// Production VPC with full configuration
const prodVpc = new Vpc(this, "ProductionVpc", {
// Network configuration
maxAzs: 3,
natGateways: 2, // HA NAT
// IPAM integration
accountId: this.account,
ipv4IpamPoolId: props.ipamPoolId,
// Custom subnets
subnetConfiguration: [
{
name: 'web',
subnetType: ec2.SubnetType.PUBLIC,
cidrMask: 24
},
{
name: 'app',
subnetType: ec2.SubnetType.PRIVATE_WITH_EGRESS,
cidrMask: 23
},
{
name: 'data',
subnetType: ec2.SubnetType.PRIVATE_ISOLATED,
cidrMask: 24
}
]
});
// Add VPC endpoints to reduce costs
prodVpc.addGatewayEndpoint('S3Endpoint', {
service: ec2.GatewayVpcEndpointAwsService.S3,
subnets: [{ subnetType: ec2.SubnetType.PRIVATE_WITH_EGRESS }]
});
prodVpc.addInterfaceEndpoint('EcrEndpoint', {
service: ec2.InterfaceVpcEndpointAwsService.ECR,
subnets: { subnetType: ec2.SubnetType.PRIVATE_WITH_EGRESS }
});
// Security group for web tier
const webSg = new ec2.SecurityGroup(this, 'WebSecurityGroup', {
vpc: prodVpc,
description: 'Web tier security group',
allowAllOutbound: true
});
webSg.addIngressRule(
ec2.Peer.anyIpv4(),
ec2.Port.tcp(443),
'Allow HTTPS from anywhere'
);
// Application deployment
const app = new EcsCluster(this, "App", {
vpc: prodVpc,
serviceName: "production-app"
});
// Database in isolated subnet
const database = new RdsAurora(this, "Database", {
vpc: prodVpc,
databaseName: "production",
vpcSubnets: {
subnetType: ec2.SubnetType.PRIVATE_ISOLATED
}
});
// Output VPC details
new CfnOutput(this, 'VpcId', {
value: prodVpc.vpcId,
description: 'VPC ID'
});
new CfnOutput(this, 'VpcCidr', {
value: prodVpc.vpcCidrBlock,
description: 'VPC CIDR block'
});