Skip to content

Commit

Permalink
Merge pull request #56 from pulumi/lukehoban/stackprops
Browse files Browse the repository at this point in the history
Support specifying stack properties
  • Loading branch information
viveklak authored Aug 12, 2022
2 parents 8fcb9a1 + f427b86 commit 381f57f
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 1 deletion.
3 changes: 3 additions & 0 deletions examples/ecscluster/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: pulumi-cdk-ecscluster
runtime: nodejs
description: ECS Cluster
34 changes: 34 additions & 0 deletions examples/ecscluster/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import * as ecs from 'aws-cdk-lib/aws-ecs';
import * as pulumi from '@pulumi/pulumi';
import * as pulumicdk from '@pulumi/cdk';
import * as ec2 from 'aws-cdk-lib/aws-ec2';
import * as pulumiaws from "@pulumi/aws-native";

class ECSClusterStack extends pulumicdk.Stack {
clusterArn: pulumi.Output<string>;

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

const vpc = ec2.Vpc.fromLookup(this, 'MyVpc', {
isDefault: true,
})
const cluster = new ecs.Cluster(this, 'fargate-service-autoscaling', { vpc });

this.clusterArn = this.asOutput(cluster.clusterArn);

this.synth();
}
}

export const clusterArn = pulumiaws.getAccountId().then(account => {
const stack = new ECSClusterStack('teststack', {
props: {
env: {
region: pulumiaws.config.region,
account: account.accountId,
}
}
});
return stack.clusterArn;
});
16 changes: 16 additions & 0 deletions examples/ecscluster/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "pulumi-aws-cdk",
"devDependencies": {
"@types/node": "^10.0.0"
},
"dependencies": {
"@pulumi/aws": "^4.6.0",
"@pulumi/aws-native": "^0.16.1",
"@pulumi/pulumi": "^3.0.0",
"aws-cdk-lib": "^2.20.0",
"constructs": "^10.0.111"
},
"peerDependencies": {
"@pulumi/cdk": "^0.0.1"
}
}
18 changes: 18 additions & 0 deletions examples/ecscluster/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"compilerOptions": {
"strict": true,
"outDir": "bin",
"target": "es2016",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"experimentalDecorators": true,
"pretty": true,
"noFallthroughCasesInSwitch": true,
"noImplicitReturns": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.ts"
]
}
9 changes: 9 additions & 0 deletions examples/examples_nodejs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ 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
7 changes: 6 additions & 1 deletion src/stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ import { zipDirectory } from './zip';
* Options specific to the Stack component.
*/
export interface StackOptions extends pulumi.ComponentResourceOptions {
/**
* Specify the CDK Stack properties to asociate with the stack.
*/
props?: cdk.StackProps;

/**
* Defines a mapping to override and/or provide an implementation for a CloudFormation resource
* type that is not (yet) implemented in the AWS Cloud Control API (and thus not yet available in
Expand Down Expand Up @@ -165,7 +170,7 @@ export class Stack extends cdk.Stack {
},
});

super(app, name);
super(app, name, options?.props);

this.app = app;
this.options = options;
Expand Down

0 comments on commit 381f57f

Please sign in to comment.