Skip to content

Commit

Permalink
Updating all examples
Browse files Browse the repository at this point in the history
  • Loading branch information
corymhall committed Oct 23, 2024
1 parent 1263a95 commit 189a0e0
Show file tree
Hide file tree
Showing 16 changed files with 203 additions and 238 deletions.
27 changes: 17 additions & 10 deletions examples/alb/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,23 @@ import * as ec2 from 'aws-cdk-lib/aws-ec2';
import * as elbv2 from 'aws-cdk-lib/aws-elasticloadbalancingv2';
import * as pulumi from '@pulumi/pulumi';
import * as pulumicdk from '@pulumi/cdk';
import { CfnOutput } from 'aws-cdk-lib';

class AlbStack extends pulumicdk.Stack {
url: pulumi.Output<string>;

constructor(id: string, options?: pulumicdk.StackOptions) {
super(id, options);
// necessary for local testing
const t = this as any;
constructor(app: pulumicdk.App, id: string) {
super(app, id);

const vpc = new ec2.Vpc(t, 'VPC');
const vpc = new ec2.Vpc(this, 'VPC');

const asg = new autoscaling.AutoScalingGroup(t, 'ASG', {
const asg = new autoscaling.AutoScalingGroup(this, 'ASG', {
vpc,
instanceType: ec2.InstanceType.of(ec2.InstanceClass.T2, ec2.InstanceSize.MICRO),
machineImage: new ec2.AmazonLinuxImage(),
});

const lb = new elbv2.ApplicationLoadBalancer(t, 'LB', {
const lb = new elbv2.ApplicationLoadBalancer(this, 'LB', {
vpc,
internetFacing: true,
});
Expand All @@ -45,10 +44,18 @@ class AlbStack extends pulumicdk.Stack {
});

this.url = this.asOutput(lb.loadBalancerDnsName);
}
}

this.synth();
class MyApp extends pulumicdk.App {
constructor() {
super('app', (scope: pulumicdk.App): pulumicdk.AppOutputs => {
const stack = new AlbStack(scope, 'teststack');
return { url: stack.url };
});
}
}

const stack = new AlbStack('teststack');
export const url = stack.url;
const app = new MyApp();

export const url = app.outputs['url'];
22 changes: 16 additions & 6 deletions examples/api-websocket-lambda-dynamodb/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { LogGroup, RetentionDays } from 'aws-cdk-lib/aws-logs';
class ChatAppStack extends pulumicdk.Stack {
public readonly url: Output<string>;
public readonly table: Output<string>;
constructor(id: string) {
super(id);
constructor(app: pulumicdk.App, id: string) {
super(app, id);

// initialise api
const name = id + '-api';
Expand Down Expand Up @@ -93,11 +93,21 @@ class ChatAppStack extends pulumicdk.Stack {

this.table = this.asOutput(table.tableName);
this.url = this.asOutput(stage.url);
}
}

this.synth();
class MyApp extends pulumicdk.App {
constructor() {
super('app', (scope: pulumicdk.App): pulumicdk.AppOutputs => {
const stack = new ChatAppStack(scope, 'chat-app');
return {
url: stack.url,
table: stack.table,
};
});
}
}

const stack = new ChatAppStack('chat-app');
export const url = stack.url;
export const table = stack.table;
const app = new MyApp();
export const url = app.outputs['url'];
export const table = app.outputs['table'];
20 changes: 12 additions & 8 deletions examples/apprunner/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import * as ecs from 'aws-cdk-lib/aws-ecs';
import * as pulumi from '@pulumi/pulumi';
import * as pulumicdk from '@pulumi/cdk';
import { Construct } from 'constructs';
import { Service, Source } from '@aws-cdk/aws-apprunner-alpha';
import { CfnOutput } from 'aws-cdk-lib';

class AppRunnerStack extends pulumicdk.Stack {
url: pulumi.Output<string>;

constructor(id: string) {
super(id);
constructor(app: pulumicdk.App, id: string) {
super(app, id);

const service = new Service(this, 'service', {
source: Source.fromEcrPublic({
Expand All @@ -19,10 +16,17 @@ class AppRunnerStack extends pulumicdk.Stack {
});

this.url = this.asOutput(service.serviceUrl);
}
}

this.synth();
class MyApp extends pulumicdk.App {
constructor() {
super('app', (scope: pulumicdk.App): pulumicdk.AppOutputs => {
const stack = new AppRunnerStack(scope, 'teststack');
return { url: stack.url };
});
}
}

const stack = new AppRunnerStack('teststack');
export const url = stack.url;
const app = new MyApp();
export const url = app.outputs['url'];
19 changes: 13 additions & 6 deletions examples/appsvc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ const azs = aws.getAvailabilityZonesOutput({
class ClusterStack extends pulumicdk.Stack {
serviceName: pulumi.Output<string>;

constructor(name: string) {
super(name);
constructor(app: pulumicdk.App, name: string) {
super(app, name);

const vpc = ec2.Vpc.fromVpcAttributes(this, 'Vpc', {
vpcId: pulumicdk.asString(defaultVpc.id),
Expand Down Expand Up @@ -80,11 +80,18 @@ class ClusterStack extends pulumicdk.Stack {
],
});

this.synth();

this.serviceName = this.asOutput(service.serviceName);
}
}

const stack = new ClusterStack('teststack');
export const serviceName = stack.serviceName;
class MyApp extends pulumicdk.App {
constructor() {
super('app', (scope: pulumicdk.App): pulumicdk.AppOutputs => {
const stack = new ClusterStack(scope, 'teststack');
return { serviceName: stack.serviceName };
});
}
}

const app = new MyApp();
export const serviceName = app.outputs['serviceName'];
17 changes: 12 additions & 5 deletions examples/cron-lambda/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import * as pulumicdk from '@pulumi/cdk';
class LambdaStack extends pulumicdk.Stack {
lambdaArn: pulumi.Output<string>;

constructor(id: string, options?: pulumicdk.StackOptions) {
super(id, options);
constructor(app: pulumicdk.App, id: string) {
super(app, id);

// Use the AWS CDK Lambda Function API directly.
const lambdaFn = new aws_lambda.Function(this, 'lambda', {
Expand All @@ -31,10 +31,17 @@ class LambdaStack extends pulumicdk.Stack {

// Export the Lambda function's ARN as an output.
this.lambdaArn = this.asOutput(lambdaFn.functionArn);
}
}

this.synth();
class MyApp extends pulumicdk.App {
constructor() {
super('app', (scope: pulumicdk.App): pulumicdk.AppOutputs => {
const stack = new LambdaStack(scope, 'teststack');
return { lambdaArn: stack.lambdaArn };
});
}
}

const stack = new LambdaStack('teststack');
export const lambdaArn = stack.lambdaArn;
const app = new MyApp();
export const lambdaArn = app.outputs['lambdaArn'];
21 changes: 14 additions & 7 deletions examples/ec2-instance/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import * as pulumicdk from '@pulumi/cdk';
import { Asset } from 'aws-cdk-lib/aws-s3-assets';

export class Ec2CdkStack extends pulumicdk.Stack {
constructor(id: string) {
super(id);
constructor(app: pulumicdk.App, id: string) {
super(app, id);

// Create a Key Pair to be used with this EC2 Instance
// Temporarily disabled since `cdk-ec2-key-pair` is not yet CDK v2 compatible
Expand Down Expand Up @@ -80,12 +80,19 @@ export class Ec2CdkStack extends pulumicdk.Stack {
new cdk.CfnOutput(this, 'ssh command', {
value: 'ssh -i cdk-key.pem -o IdentitiesOnly=yes ec2-user@' + ec2Instance.instancePublicIp,
});
}
}

this.synth();
class MyApp extends pulumicdk.App {
constructor() {
super('app', (scope: pulumicdk.App) => {
new Ec2CdkStack(scope, 'teststack');
});
}
}

const stack = new Ec2CdkStack('teststack');
export const ipAddress = stack.outputs['IP Address'];
export const keyCommand = stack.outputs['Download Key Command'];
export const sshCommand = stack.outputs['sshCommand'];
const app = new MyApp();

export const ipAddress = app.outputs['IP Address'];
export const keyCommand = app.outputs['Download Key Command'];
export const sshCommand = app.outputs['sshCommand'];
3 changes: 0 additions & 3 deletions examples/ecscluster/Pulumi.yaml

This file was deleted.

34 changes: 0 additions & 34 deletions examples/ecscluster/index.ts

This file was deleted.

14 changes: 0 additions & 14 deletions examples/ecscluster/package.json

This file was deleted.

18 changes: 0 additions & 18 deletions examples/ecscluster/tsconfig.json

This file was deleted.

21 changes: 12 additions & 9 deletions examples/examples_nodejs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,6 @@ func TestAppSvc(t *testing.T) {
integration.ProgramTest(t, &test)
}

func TestECSCluster(t *testing.T) {
test := getJSBaseOptions(t).
With(integration.ProgramTestOptions{
Dir: filepath.Join(getCwd(t), "ecscluster"),
})

integration.ProgramTest(t, &test)
}

func TestAppRunner(t *testing.T) {
test := getJSBaseOptions(t).
With(integration.ProgramTestOptions{
Expand Down Expand Up @@ -102,6 +93,18 @@ func TestEC2Instance(t *testing.T) {
integration.ProgramTest(t, &test)
}

func TestLookups(t *testing.T) {
test := getJSBaseOptions(t).
With(integration.ProgramTestOptions{
Dir: filepath.Join(getCwd(t), "lookups"),
Config: map[string]string{
"zoneName": "coolcompany.io",
},
})

integration.ProgramTest(t, &test)
}

func TestAPIWebsocketLambdaDynamoDB(t *testing.T) {
test := getJSBaseOptions(t).
With(integration.ProgramTestOptions{
Expand Down
18 changes: 12 additions & 6 deletions examples/fargate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { CfnTargetGroup } from 'aws-cdk-lib/aws-elasticloadbalancingv2';
class FargateStack extends pulumicdk.Stack {
loadBalancerDNS: pulumi.Output<string>;

constructor(id: string, options?: pulumicdk.StackOptions) {
super(id, options);
constructor(app: pulumicdk.App, id: string) {
super(app, id);

// Create VPC and Fargate Cluster
// NOTE: Limit AZs to avoid reaching resource quotas
Expand Down Expand Up @@ -46,11 +46,17 @@ class FargateStack extends pulumicdk.Stack {
});

this.loadBalancerDNS = this.asOutput(fargateService.loadBalancer.loadBalancerDnsName);
}
}

// Finalize the stack and deploy its resources.
this.synth();
class MyApp extends pulumicdk.App {
constructor() {
super('app', (scope: pulumicdk.App): pulumicdk.AppOutputs => {
const stack = new FargateStack(scope, 'fargatestack');
return { loadBalancerURL: stack.loadBalancerDNS };
});
}
}

const stack = new FargateStack('fargatestack');
export const loadBalancerURL = stack.loadBalancerDNS;
const app = new MyApp();
export const loadBalancerURL = app.outputs['loadBalancerURL'];
Loading

0 comments on commit 189a0e0

Please sign in to comment.