diff --git a/infra/bin/infra.ts b/infra/bin/infra.ts index e9658b4..3844bbd 100644 --- a/infra/bin/infra.ts +++ b/infra/bin/infra.ts @@ -3,12 +3,30 @@ import "source-map-support/register"; import * as cdk from "aws-cdk-lib"; import { InfraStack } from "../lib/infra-stack"; +// CIDR allocation strategy: +// Top: 10.15.0.0/16 +// VPCs: 10.15.0.0/18, 10.15.64.0/18, 10.15.128.0/18, 10.15.192.0/18 (16382 addresses) +// Subnets: ... + const accounts = { - dev: { account: "682033502734", region: "eu-west-1" }, + dev: { + account: "682033502734", + region: "eu-west-1", + }, + network: { + cidrs: { + dev: "10.15.0.0/18", + }, + maxAzs: { + dev: 2, + }, + }, }; const app = new cdk.App(); -new InfraStack(app, "InfraStack", { +const devStack = new InfraStack(app, "InfraStack", { env: accounts.dev, + cidrBlock: accounts.network.cidrs.dev, + maxAzs: accounts.network.maxAzs.dev, }); diff --git a/infra/cdk.context.json b/infra/cdk.context.json new file mode 100644 index 0000000..8dc216c --- /dev/null +++ b/infra/cdk.context.json @@ -0,0 +1,7 @@ +{ + "availability-zones:account=682033502734:region=eu-west-1": [ + "eu-west-1a", + "eu-west-1b", + "eu-west-1c" + ] +} diff --git a/infra/lib/infra-stack.ts b/infra/lib/infra-stack.ts index d94b847..0e9a85c 100644 --- a/infra/lib/infra-stack.ts +++ b/infra/lib/infra-stack.ts @@ -1,8 +1,19 @@ import * as cdk from "aws-cdk-lib"; import { Construct } from "constructs"; +import * as ec2 from "aws-cdk-lib/aws-ec2"; + +export interface InfraStackProps extends cdk.StackProps { + cidrBlock: string; + maxAzs: number; +} export class InfraStack extends cdk.Stack { - constructor(scope: Construct, id: string, props?: cdk.StackProps) { + constructor(scope: Construct, id: string, props: InfraStackProps) { super(scope, id, props); + + const vpc = new ec2.Vpc(this, "Vpc", { + ipAddresses: ec2.IpAddresses.cidr(props.cidrBlock), + maxAzs: props.maxAzs, + }); } }