diff --git a/README.md b/README.md index 1f45df92..f1160a43 100644 --- a/README.md +++ b/README.md @@ -106,7 +106,7 @@ Add a minimal VPC to your Pulumi program: ```ts import * as studion from '@studion/infra-code-blocks'; -const vpc = new studion.Vpc('app', {}); +const vpc = new studion.Vpc('app'); export const vpcId = vpc.vpc.vpcId; ``` @@ -142,7 +142,7 @@ const hostedZone = aws.route53.getZoneOutput({ privateZone: false, }); -const vpc = new studion.Vpc('app', {}); +const vpc = new studion.Vpc('app'); const certificate = new studion.AcmCertificate('app-cert', { domain: 'app.example.com', @@ -163,7 +163,7 @@ import * as pulumi from '@pulumi/pulumi'; import * as studion from '@studion/infra-code-blocks'; const env = pulumi.getStack(); -const vpc = new studion.Vpc('app', {}); +const vpc = new studion.Vpc('app'); const cluster = new aws.ecs.Cluster('app-cluster', {}); const logGroup = new aws.cloudwatch.LogGroup('app-otel-logs', {}); const workspace = new aws.amp.Workspace('app-amp', {}); @@ -222,7 +222,7 @@ Use the database builder when you want the database and helper instance created ```ts import * as studion from '@studion/infra-code-blocks'; -const vpc = new studion.Vpc('platform', {}); +const vpc = new studion.Vpc('platform'); const database = new studion.DatabaseBuilder('platform-db') .withVpc(vpc.vpc) @@ -241,7 +241,7 @@ You can also provision `Ec2SSMConnect` directly when you want a standalone helpe ```ts import * as studion from '@studion/infra-code-blocks'; -const vpc = new studion.Vpc('platform', {}); +const vpc = new studion.Vpc('platform'); const ssmConnect = new studion.Ec2SSMConnect('platform-db-ssm', { vpc: vpc.vpc, diff --git a/src/components/database/README.md b/src/components/database/README.md index 1a4e2aab..b4fc1db4 100644 --- a/src/components/database/README.md +++ b/src/components/database/README.md @@ -11,7 +11,7 @@ Use `Database` or `DatabaseBuilder` when you want secure-by-default networking, ```ts import * as studion from '@studion/infra-code-blocks'; -const vpc = new studion.Vpc('app', {}); +const vpc = new studion.Vpc('app'); const database = new studion.DatabaseBuilder('app-db') .withVpc(vpc.vpc) @@ -28,7 +28,7 @@ export const passwordSecretArn = database.password.secret.arn; ```ts import * as studion from '@studion/infra-code-blocks'; -const vpc = new studion.Vpc('platform', {}); +const vpc = new studion.Vpc('platform'); const database = new studion.Database('platform-db', { vpc: vpc.vpc, diff --git a/src/components/ecs-service/README.md b/src/components/ecs-service/README.md index c6d741a9..aab0ba69 100644 --- a/src/components/ecs-service/README.md +++ b/src/components/ecs-service/README.md @@ -12,7 +12,7 @@ Use it when you need ECS service plumbing—task definition, IAM roles, logging, import * as aws from '@pulumi/aws'; import * as studion from '@studion/infra-code-blocks'; -const vpc = new studion.Vpc('app', {}); +const vpc = new studion.Vpc('app'); const cluster = new aws.ecs.Cluster('app-cluster', {}); const ecsService = new studion.EcsService('worker', { @@ -37,7 +37,7 @@ export const logGroupName = ecsService.logGroup.name; import * as aws from '@pulumi/aws'; import * as studion from '@studion/infra-code-blocks'; -const vpc = new studion.Vpc('internal', {}); +const vpc = new studion.Vpc('internal'); const cluster = new aws.ecs.Cluster('internal-cluster', {}); const taskRolePolicy: aws.types.input.iam.RoleInlinePolicy = { diff --git a/src/components/redis/README.md b/src/components/redis/README.md index 3ae5e763..ca7513cb 100644 --- a/src/components/redis/README.md +++ b/src/components/redis/README.md @@ -11,7 +11,7 @@ Use these components for caches, session stores, queues, and other low-latency s ```ts import { ElastiCacheRedis, Vpc } from '@studion/infra-code-blocks'; -const vpc = new Vpc('app', {}); +const vpc = new Vpc('app'); const cache = new ElastiCacheRedis('app-cache', { vpc: vpc.vpc, diff --git a/src/components/vpc/README.md b/src/components/vpc/README.md index ebcb48cc..1ef60363 100644 --- a/src/components/vpc/README.md +++ b/src/components/vpc/README.md @@ -11,7 +11,7 @@ Use it as the shared networking foundation for components such as `Database`, `E ```ts import { Vpc } from '@studion/infra-code-blocks'; -const vpc = new Vpc('app', {}); +const vpc = new Vpc('app'); export const vpcId = vpc.vpc.vpcId; ``` @@ -63,12 +63,12 @@ class Vpc extends pulumi.ComponentResource { | Name | Type | Required | Default | Description | | ------ | --------------------------------- | -------- | ------- | ------------------------------------------- | | `name` | `string` | Yes | none | Logical Pulumi component name. | -| `args` | `VpcArgs` | Yes | none | Direct VPC configuration object. | +| `args` | `Vpc.Args` | No | `{}` | Direct VPC configuration object. | | `opts` | `pulumi.ComponentResourceOptions` | No | none | Optional Pulumi component resource options. | **Configuration Options** -Direct constructor input: `args: VpcArgs` +Direct constructor input: `args: Vpc.Args` | Name | Type | Required | Default | Description | | --------------------------- | ------------------------------------------------------- | -------- | ------- | ------------------------------------------------- | diff --git a/src/components/vpc/index.ts b/src/components/vpc/index.ts index c02dbb56..a1eb2f4c 100644 --- a/src/components/vpc/index.ts +++ b/src/components/vpc/index.ts @@ -4,18 +4,20 @@ import { commonTags } from '../../shared/common-tags'; import { enums } from '@pulumi/awsx/types'; import { mergeWithDefaults } from '../../shared/merge-with-defaults'; -export type VpcArgs = { - /** - * Number of availability zones to which the subnets defined in subnetSpecs will be deployed - * @default '2' - */ - numberOfAvailabilityZones?: number; - tags?: pulumi.Input<{ - [key: string]: pulumi.Input; - }>; -}; +export namespace Vpc { + export type Args = { + /** + * Number of availability zones to which the subnets defined in subnetSpecs will be deployed + * @default '2' + */ + numberOfAvailabilityZones?: number; + tags?: pulumi.Input<{ + [key: string]: pulumi.Input; + }>; + }; +} -export const defaults = { +const defaults = { numberOfAvailabilityZones: 2, }; @@ -24,7 +26,7 @@ export class Vpc extends pulumi.ComponentResource { constructor( name: string, - args: VpcArgs, + args: Vpc.Args = {}, opts: pulumi.ComponentResourceOptions = {}, ) { super('studion:vpc:Vpc', name, {}, opts); diff --git a/src/components/web-server/README.md b/src/components/web-server/README.md index a8884f45..9db367fe 100644 --- a/src/components/web-server/README.md +++ b/src/components/web-server/README.md @@ -12,7 +12,7 @@ Use it when a workload needs package-standard public HTTP/HTTPS ingress, load-ba import * as aws from '@pulumi/aws'; import * as studion from '@studion/infra-code-blocks'; -const vpc = new studion.Vpc('app', {}); +const vpc = new studion.Vpc('app'); const cluster = new aws.ecs.Cluster('app-cluster', {}); const webServer = new studion.WebServerBuilder('app') @@ -38,7 +38,7 @@ export const serviceName = webServer.service.apply( import * as aws from '@pulumi/aws'; import * as studion from '@studion/infra-code-blocks'; -const vpc = new studion.Vpc('platform', {}); +const vpc = new studion.Vpc('platform'); const cluster = new aws.ecs.Cluster('platform-cluster', {}); const certificate = new aws.acm.Certificate('platform-cert', { diff --git a/src/otel/README.md b/src/otel/README.md index 85158bc9..a9514049 100644 --- a/src/otel/README.md +++ b/src/otel/README.md @@ -28,7 +28,7 @@ import * as pulumi from '@pulumi/pulumi'; import * as studion from '@studion/infra-code-blocks'; const env = pulumi.getStack(); -const vpc = new studion.Vpc('app', {}); +const vpc = new studion.Vpc('app'); const cluster = new aws.ecs.Cluster('app-cluster', {}); const logGroup = new aws.cloudwatch.LogGroup('otel-logs', { retentionInDays: 7, diff --git a/tests/vpc/index.test.ts b/tests/vpc/index.test.ts index 191d5233..8777f648 100644 --- a/tests/vpc/index.test.ts +++ b/tests/vpc/index.test.ts @@ -13,7 +13,6 @@ import { SubnetState, VpcState, } from '@aws-sdk/client-ec2'; -import { defaults as vpcDefaults } from '../../src/components/vpc'; const programArgs: InlineProgramArgs = { stackName: 'dev', @@ -40,12 +39,7 @@ describe('Vpc component deployment', () => { it('should create a default VPC with the correct configuration', async () => { const defaultVpc = ctx.outputs.defaultVpc.value; - await testVpcConfiguration( - ctx, - defaultVpc.vpc.vpcId, - 6, - vpcDefaults.numberOfAvailabilityZones, - ); + await testVpcConfiguration(ctx, defaultVpc.vpc.vpcId, 6, 2); }); it('should create a VPC with the correct configuration', async () => { @@ -103,11 +97,7 @@ describe('Vpc component deployment', () => { }), ); const natGateways = natGwResult.NatGateways || []; - assert.strictEqual( - natGateways.length, - vpcDefaults.numberOfAvailabilityZones, - `Should have ${vpcDefaults.numberOfAvailabilityZones} NAT gateways`, - ); + assert.strictEqual(natGateways.length, 2, `Should have 2 NAT gateways`); natGateways.forEach(nat => { assert.strictEqual( diff --git a/tests/vpc/infrastructure/index.ts b/tests/vpc/infrastructure/index.ts index 4f9391aa..45412e85 100644 --- a/tests/vpc/infrastructure/index.ts +++ b/tests/vpc/infrastructure/index.ts @@ -8,7 +8,7 @@ const tags = { Environment: stackName, }; -const defaultVpc = new studion.Vpc(`${appName}-default`, {}); +const defaultVpc = new studion.Vpc(`${appName}-default`); const vpc = new studion.Vpc(`${appName}`, { numberOfAvailabilityZones: 3,