-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use cdk-cli-lib to synthesize CDK application #170
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f2248ec
Use cdk-cli-lib to synthesize CDK application
corymhall 2395e3d
Fixing rebase conflicts
corymhall 1b78a9e
fixing some stuff
corymhall 24cd053
fixing build issues
corymhall 2f78143
fixing deps
corymhall 9eec898
fixing lookup
corymhall 5b08629
Add adr
corymhall b613347
cleaning up the api and updating README
corymhall 176d9b2
fixing dep
corymhall 42df90a
rebasing upstream examples
corymhall fd02d81
revert workflow changes
corymhall 37dcabb
updating based on review comments
corymhall File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,3 +118,4 @@ test-reports/ | |
lib/ | ||
|
||
**/cdk.out | ||
**/cdk.context.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,22 @@ | ||
# Pulumi CDK Adapter (preview) | ||
|
||
The Pulumi CDK Adapter is a library that enables [Pulumi](https://github.com/pulumi/pulumi) programs to use [AWS CDK](https://github.com/aws/aws-cdk) constructs. | ||
The Pulumi CDK Adapter is a library that enables | ||
[Pulumi](https://github.com/pulumi/pulumi) programs to use [AWS | ||
CDK](https://github.com/aws/aws-cdk) constructs. | ||
|
||
The adapter allows writing AWS CDK code as part of an AWS CDK Stack inside a Pulumi program, and having the resulting AWS resources be deployed and managed via Pulumi. Outputs of resources defined in a Pulumi program can be passed into AWS CDK Constructs, and outputs from AWS CDK stacks can be used as inputs to other Pulumi resources. | ||
The adapter allows writing AWS CDK code as part of an AWS CDK Stack inside a | ||
Pulumi program, and having the resulting AWS resources be deployed and managed | ||
via Pulumi. Outputs of resources defined in a Pulumi program can be passed | ||
into AWS CDK Constructs, and outputs from AWS CDK stacks can be used as inputs | ||
to other Pulumi resources. | ||
|
||
> Note: Currently, the Pulumi CDK Adapter preview is available only for TypeScript/JavaScript users. | ||
> Note: Currently, the Pulumi CDK Adapter preview is available only for | ||
> TypeScript/JavaScript users. | ||
|
||
For example, to construct an [AWS AppRunner `Service` resource](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-apprunner-alpha-readme.html) from within a Pulumi program, and export the resulting service's URL as as Pulumi Stack Output you write the following: | ||
For example, to construct an [AWS AppRunner `Service` | ||
resource](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-apprunner-alpha-readme.html) | ||
from within a Pulumi program, and export the resulting service's URL as as | ||
Pulumi Stack Output you write the following: | ||
|
||
```ts | ||
import * as pulumi from '@pulumi/pulumi'; | ||
|
@@ -27,18 +37,21 @@ class AppRunnerStack extends pulumicdk.Stack { | |
}); | ||
|
||
this.url = this.asOutput(service.serviceUrl); | ||
|
||
this.synth(); | ||
} | ||
} | ||
|
||
const stack = new AppRunnerStack('teststack'); | ||
export const url = stack.url; | ||
const app = new pulumicdk.App('app', (scope: pulumicdk.App): pulumicdk.AppOutputs => { | ||
const stack = new AppRunnerStack('teststack'); | ||
return { | ||
url: stack.url, | ||
}; | ||
}); | ||
export const url = app.outputs['url']; | ||
``` | ||
|
||
And then deploy with `pulumi update`: | ||
|
||
``` | ||
```console | ||
> pulumi up | ||
|
||
Updating (dev) | ||
|
@@ -60,7 +73,7 @@ Resources: | |
|
||
And curl the endpoint: | ||
|
||
``` | ||
```console | ||
> curl https://$(pulumi stack output url) | ||
|
||
______ __ __ __ _ __ | ||
|
@@ -81,99 +94,135 @@ Try the workshop at https://apprunnerworkshop.com | |
Read the docs at https://docs.aws.amazon.com/apprunner | ||
``` | ||
|
||
## Getting Started | ||
## Bootstrapping | ||
|
||
CDK has the concept of [bootstrapping](https://docs.aws.amazon.com/cdk/v2/guide/bootstrapping.html) | ||
which requires you to first bootstrap your account with certain AWS resources | ||
that CDK needs to exist. With Pulumi CDK this is not required! Pulumi CDK will | ||
automatically and dynamically create the bootstrap resources as needed. | ||
|
||
### Bootstrapping | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We now auto-bootstrap? Perhaps still worth a mention that it does this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added some docs around bootstrapping and what resources we create for you. |
||
### S3 Resources | ||
|
||
AWS CDK requires that your AWS account and target region are "bootstrapped" for use with CDK, so in order to use CDK on Pulumi, you'll need to do that first. We recommend using the latest bootstrap template (v2, as of this writing). [See the AWS documentation](https://docs.aws.amazon.com/cdk/v2/guide/bootstrapping.html) for details. (Note that resources deployed with Pulumi on CDK are deployed and managed with Pulumi, not CloudFormation; the bootstrapping step is required by CDK for additional runtime support.) | ||
When any file assets are added to your application, CDK will automatically | ||
create the following staging resources. | ||
|
||
1. [aws.s3.BucketV2](https://www.pulumi.com/registry/packages/aws/api-docs/s3/bucketv2/) | ||
- `forceDestroy`: true | ||
2. [aws.s3.BucketServerSideEncryptionConfigurationV2](https://www.pulumi.com/registry/packages/aws/api-docs/s3/bucketserversideencryptionconfigurationv2/) | ||
- `AES256` | ||
3. [aws.s3.BucketVersioningV2](https://www.pulumi.com/registry/packages/aws/api-docs/s3/bucketversioningv2/) | ||
- `Enabled` | ||
4. [aws.s3.BucketLifecycleConfigurationV2](https://www.pulumi.com/registry/packages/aws/api-docs/s3/bucketlifecycleconfigurationv2/) | ||
- Expire old versions > 365 days | ||
- Expire deploy-time assets > 30 days | ||
5. [aws.s3.BucketPolicy](https://www.pulumi.com/registry/packages/aws/api-docs/s3/bucketpolicy/) | ||
- Require SSL | ||
|
||
## API | ||
|
||
### `Stack` | ||
### `App` | ||
|
||
A Construct that represents an AWS CDK stack deployed with Pulumi. In order to deploy a CDK stack with Pulumi, it must derive from this class. The `synth` method must be called after all CDK resources have been defined in order to deploy the stack (usually, this is done as the last line of the subclass's constructor). | ||
A Pulumi CDK App component. This is the entrypoint to your Pulumi CDK application. | ||
In order to deploy a CDK application with Pulumi, you must start with this class. | ||
|
||
#### `constructor` | ||
|
||
Create and register an AWS CDK stack deployed with Pulumi. | ||
Create and register an AWS CDK app deployed with Pulumi. | ||
|
||
```ts | ||
constructor(name: string, options?: StackOptions) | ||
constructor(id: string, createFunc: (scope: App) => void | AppOutputs, props?: AppResourceOptions) | ||
``` | ||
|
||
Parameters: | ||
* `name`: The _unique_ name of the resource. | ||
* `options`: A bag of options that control this resource's behavior. | ||
|
||
### `urn` | ||
|
||
The URN of the underlying Pulumi component. | ||
* `id`: The _unique_ name of the app | ||
* `createFunc`: A callback function where all CDK Stacks must be created | ||
* `options`: A bag of options that control the resource's behavior | ||
|
||
#### `outputs` | ||
|
||
The collection of outputs from the AWS CDK Stack represented as Pulumi Outputs. Each `CfnOutput` defined in the AWS CDK Stack will populate a value in the outputs. | ||
The collection of outputs from the Pulumi CDK App represented as Pulumi Outputs. | ||
Each `CfnOutput` defined in each AWS CDK Stack will populate a value in the | ||
outputs. | ||
|
||
```ts | ||
outputs: { [outputId: string]: pulumi.Output<any> } | ||
``` | ||
|
||
#### `synth` | ||
|
||
Finalize the stack and deploy its resources. | ||
|
||
```ts | ||
protected synth() | ||
``` | ||
#### `AppResourceOptions` | ||
|
||
#### `asOutput` | ||
|
||
Convert a CDK value to a Pulumi output. | ||
|
||
Parameters: | ||
* `v`: A CDK value. | ||
|
||
```ts | ||
asOutput<T>(v: T): pulumi.Output<T> | ||
``` | ||
|
||
### `StackOptions` | ||
|
||
Options specific to the Stack component. | ||
Options specific to the App Component | ||
|
||
```ts | ||
interface StackOptions | ||
interface AppResourceOptions | ||
``` | ||
|
||
#### `remapCloudControlResource` | ||
|
||
This optional method can be implemented to define 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 the Pulumi AWS Native provider). Pulumi code can override this method to provide a custom mapping of CloudFormation elements and their properties into Pulumi CustomResources, commonly by using the AWS Classic provider to implement the missing resource. | ||
This optional method can be implemented to define 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 the | ||
Pulumi AWS Native provider). Pulumi code can override this method to provide a | ||
custom mapping of CloudFormation elements and their properties into Pulumi | ||
CustomResources, commonly by using the AWS Classic provider to implement the | ||
missing resource. | ||
|
||
```ts | ||
remapCloudControlResource(element: CfnElement, logicalId: string, typeName: string, props: any, options: pulumi.ResourceOptions): { [key: string]: pulumi.CustomResource } | undefined | ||
remapCloudControlResource(logicalId: string, typeName: string, props: any, options: pulumi.ResourceOptions): { [key: string]: pulumi.CustomResource } | undefined | ||
``` | ||
|
||
Parameters: | ||
* `element`: The full CloudFormation element object being mapped. | ||
* `logicalId`: The logical ID of the resource being mapped. | ||
* `typeName`: The CloudFormation type name of the resource being mapped. | ||
* `props`: The bag of input properties to the CloudFormation resource being mapped. | ||
* `options`: The set of Pulumi ResourceOptions to apply to the resource being mapped. | ||
|
||
Returns an object containing one or more logical IDs mapped to Pulumi resources that must be created to implement the mapped CloudFormation resource, or else undefined if no mapping is implemented. | ||
Returns an object containing one or more logical IDs mapped to Pulumi resources | ||
that must be created to implement the mapped CloudFormation resource, or else | ||
undefined if no mapping is implemented. | ||
|
||
#### `appId` | ||
|
||
This is a unique identifier for the application. It will be used in the names of the | ||
staging resources created for the application. This `appId` should be unique across apps. | ||
|
||
### `Stack` | ||
|
||
A Construct that represents an AWS CDK stack deployed with Pulumi. In order to | ||
deploy a CDK stack with Pulumi, it must derive from this class. | ||
|
||
#### `create` | ||
#### `constructor` | ||
|
||
Create and register an AWS CDK stack deployed with Pulumi. | ||
|
||
```ts | ||
create(name: string, ctor: typeof Stack, opts?: pulumi.CustomResourceOptions): StackComponent | ||
constructor(app: App, name: string, options?: StackOptions) | ||
``` | ||
|
||
Parameters: | ||
* `app`: The Pulumi CDK App | ||
* `name`: The _unique_ name of the resource. | ||
flostadler marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* `stack`: The CDK Stack subclass to create. | ||
* `parent`: The Pulumi CDKStackComponent parent resource. | ||
* `opts`: A bag of options that control this resource's behavior. | ||
* `options`: A bag of options that control this resource's behavior. | ||
|
||
|
||
#### `asOutput` | ||
|
||
Convert a CDK value to a Pulumi output. | ||
|
||
Parameters: | ||
* `v`: A CDK value. | ||
|
||
```ts | ||
asOutput<T>(v: T): pulumi.Output<T> | ||
``` | ||
|
||
### `StackOptions` | ||
|
||
Options specific to the Stack component. | ||
|
||
```ts | ||
interface StackOptions | ||
``` | ||
|
||
|
||
### `asString` | ||
|
||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this change necessary? Looks like Emacs fil-paragraph got applied. I think we prefer to have the previous form.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know, I kind of prefer the 80 line length limit. It makes looking/editing so much easier. It's also the default in most markdown linters, (e.g. markdownlint
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AH nice, one of those things that'd just nice to have a standard. We can adopt it in the project. I'll setup column width 80 in Emacs.