Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
```
Expand Down Expand Up @@ -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',
Expand All @@ -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', {});
Expand Down Expand Up @@ -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)
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/components/database/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/components/ecs-service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand All @@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion src/components/redis/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions src/components/vpc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
```
Expand Down Expand Up @@ -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 |
| --------------------------- | ------------------------------------------------------- | -------- | ------- | ------------------------------------------------- |
Expand Down
26 changes: 14 additions & 12 deletions src/components/vpc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>;
}>;
};
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<string>;
}>;
};
}

export const defaults = {
const defaults = {
numberOfAvailabilityZones: 2,
};

Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/components/web-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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', {
Expand Down
2 changes: 1 addition & 1 deletion src/otel/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 2 additions & 12 deletions tests/vpc/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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 () => {
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion tests/vpc/infrastructure/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down