Skip to content
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

feat(cli): CDK Migrate CLI command #27325

Merged
merged 27 commits into from
Oct 6, 2023
Merged
Changes from 13 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
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
106 changes: 106 additions & 0 deletions packages/aws-cdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ The AWS CDK Toolkit provides the `cdk` command-line interface that can be used t
| [`cdk diff`](#cdk-diff) | Diff stacks against current state |
| [`cdk deploy`](#cdk-deploy) | Deploy a stack into an AWS account |
| [`cdk import`](#cdk-import) | Import existing AWS resources into a CDK stack |
| [`cdk migrate`](#cdk-migrate) | Convert an existing CFN template into a CDK Application |
| [`cdk watch`](#cdk-watch) | Watches a CDK app for deployable and hotswappable changes |
| [`cdk destroy`](#cdk-destroy) | Deletes a stack from an AWS account |
| [`cdk bootstrap`](#cdk-bootstrap) | Deploy a toolkit stack to support deploying large stacks & artifacts |
Expand Down Expand Up @@ -560,6 +561,111 @@ This feature is currently in preview. Be aware of the following limitations:
in the right order. The CLI will not help you import dependent resources in the right
order, the CloudFormation deployment will fail with unresolved references.


### `cdk migrate`

⚠️**CAUTION**⚠️

CDK migrate is currently experimental and may have breaking changes in the future.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine to open with this, but immediately below should be a paragraph explaining what this command does at a high level, including an example of simplest, minimal usage, eg only using required flags / options. It should explain where the output goes and what the output is. I should not have to guess if it's a full CDK directory or if it's a single stack file.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is capitalized almost everywhere else. It's important to be consistent.

Suggested change
CDK migrate is currently experimental and may have breaking changes in the future.
CDK Migrate is currently experimental and may have breaking changes in the future.


Generates a CDK application from an existing JSON/YAML CloudFormation template.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that this and the sentences below are in paragraph form, not bullet form, these should be complete sentences.

Takes a valid CloudFormation template as input from either a local file specified with `--from-path`,
or from a deployed Cloudformation stack using `--from-stack`. Generates a CDK application
HBobertz marked this conversation as resolved.
Show resolved Hide resolved
which will synthesize a CloudFormation template with identical resource configurations to the provided template.
The generated application will be initialized in the current working directory with a single stack where
the stack, app, and directory will all be named using the provided `--stack-name`. The generated application will
be within a generated subdirectory in your current working directory unless `--output-path` is specified.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe note somewhere in here that if a directory already exists with the stack name at the output path (or currently directory) it will be replaced with the new app folder.

All CDK supported lanaguages are supported, language choice can be specified with `--language`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
All CDK supported lanaguages are supported, language choice can be specified with `--language`.
All CDK supported languages are supported, language choice can be specified with `--language`.


#### Generate a typescript application from a local template.json file
comcalvi marked this conversation as resolved.
Show resolved Hide resolved

```console
$ # template.json is a valid cloudformation template in the local directory
$ cdk migrate --from-path ./template.json --stack-name MyAwesomeApplication
```

This command will generate a new direcotry named `MyAwesomeApplication` within your current working directory, and
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This command will generate a new direcotry named `MyAwesomeApplication` within your current working directory, and
This command will generate a new directory named `MyAwesomeApplication` within your current working directory, and

then initialize a new CDK application within that directory which has the same resource configuration as the
as the provided template.json
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
then initialize a new CDK application within that directory which has the same resource configuration as the
as the provided template.json
then initialize a new CDK application within that directory which has the same resource configuration
as the provided template.json


This results in a CDK application with the following structure, where the lib directory contains a stack definition
with the same resource configuration as the provided template.json.

```console
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also doesn't match the command you provide above. Both the naming and the language are different.

├── README.md
├── bin
│ └── my_awesome_application.ts
├── cdk.json
├── cdk.out
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we remove cdk.out since it won't exist until after synth?

│ ├── MyAwesomeApplication.assets.json
│ ├── MyAwesomeApplication.template.json
│ ├── cdk.out
│ ├── manifest.json
│ ├── synth.lock
│ └── tree.json
├── jest.config.js
├── lib
│ └── my_awesome_application-stack.ts
```

#### Generate a python application from a deployed stack

If you already had a cloudformation stack deployed in your account and would like to migrate to using CDK instead of Cloudformation.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
If you already had a cloudformation stack deployed in your account and would like to migrate to using CDK instead of Cloudformation.
If you already had a CloudFormation stack deployed in your account and would like to migrate to using CDK instead of CloudFormation.

You can use the `--from-stack` option to generate the application. In this case the `--stack-name` must match the name of the deployed stack.

```console
$ # generate a python application from MyDeployedStack in your acount
$ cdk bootstrap migrate --stack-name MyDeployedStack --language python --from-stack
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$ cdk bootstrap migrate --stack-name MyDeployedStack --language python --from-stack
$ cdk migrate --stack-name MyDeployedStack --language python --from-stack

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

woops good catch.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one still needs to be fixed

```

This will generate a python CDK application which will synthesize to the same configuration of resources as the deployed stack.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This will generate a python CDK application which will synthesize to the same configuration of resources as the deployed stack.
This will generate a Python CDK application which will synthesize to the same configuration of resources as the deployed stack.


#### **CDK Migrate Limitations**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good to call out support for Custom Resources.

Copy link
Contributor Author

@HBobertz HBobertz Oct 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this and nested stacks

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, and ADC regions will depend on those resources existing in those regions. The app will still synth but may not deploy


CDK Migrate does not currently support nested stacks, Custom resources, or ForEach intrinsic function.
HBobertz marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
CDK Migrate does not currently support nested stacks, Custom resources, or ForEach intrinsic function.
CDK Migrate does not currently support nested stacks, AWS CloudFormation Custom Resources, or the `Fn::ForEach` intrinsic function.

CDK Migrate will only generate L1 constructs and does not currently support any higher level abstractions.
CDK Migrate succesfully generating an application does *not* guarantee the application is immediately deployable.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
CDK Migrate succesfully generating an application does *not* guarantee the application is immediately deployable.
CDK Migrate successfully generating an application does *not* guarantee the application is immediately deployable.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe make this section bullet points for easier reading.

It simply generates a CDK application which will synthesize a template that has identical resource configurations
to the provided template. CDK Migrate does not interact with the CloudFormation service to verify the template
provided can deploy on it's own, nor does it validate that any resources in the provided template are already managed
HBobertz marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
provided can deploy on it's own, nor does it validate that any resources in the provided template are already managed
provided can deploy on its own, nor does it validate that any resources in the provided template are already managed

in other CloudFormation Templates. In practice this is how CDK Migrate generated applications will
operate in the following scenarios:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe also call out that if the template has has parameters without default values, the customer will need to fill those in manually


##### **The provided template is already deployed to cloudformation in the account/region**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
##### **The provided template is already deployed to cloudformation in the account/region**
##### **The provided template is already deployed to CloudFormation in the account/region**


If the provided template came directly from a deployed cloudformation stack, and that stack has not experienced any drift,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
If the provided template came directly from a deployed cloudformation stack, and that stack has not experienced any drift,
If the provided template came directly from a deployed CloudFormation stack, and that stack has not experienced any drift,

then the generated application will be immediately deployable, and will not cause any changes to the deployed resources.
Drift might occur if a resource in your template was modified outside of CloudFormation, namely via the console or CLI.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Drift might occur if a resource in your template was modified outside of CloudFormation, namely via the console or CLI.
Drift might occur if a resource in your template was modified outside of CloudFormation, namely via the AWS Console or AWS CLI.


##### **The provided template is not deployed to cloudformation in the account/region, and there *is not* overlap with with resources outside the template**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
##### **The provided template is not deployed to cloudformation in the account/region, and there *is not* overlap with with resources outside the template**
##### **The provided template is not deployed to CloudFormation in the account/region, and there *is not* overlap with existing resources in the account/region**


If the provided template represents a set of resources that have no overlap with resources already deployed in the account/region,
then the generated application will be immediately deployable. A common reason for this might be because the template came
from a stack deployed in another account/region.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A common reason for this might be

A common reason for what?


In practice this means for any resource in the provided template. i.e.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"i.e." means "that is", and "e.g." means "for example". I think it's better not to use those anyway.

Suggested change
In practice this means for any resource in the provided template. i.e.
In practice this means for any resource in the provided template, for example,


```Json
"S3Bucket": {
"Type": "AWS::S3::Bucket",
"Properties": {
"BucketName": "MyBucket",
"AccessControl": "PublicRead",
},
"DeletionPolicy": "Retain"
}
```

There must not exist a resource of that type with the same name aka "MyBucket"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
There must not exist a resource of that type with the same name aka "MyBucket"
There must not exist a resource of that type with the same name, e.g. "MyBucket"


##### **The provided template is not deployed to cloudformation in the account/region, and there *is* overlap with with resources outside the template**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
##### **The provided template is not deployed to cloudformation in the account/region, and there *is* overlap with with resources outside the template**
##### **The provided template is not deployed to CloudFormation in the account/region, and there *is* overlap with existing resources in the account/region**


If the provided template represents a set of resources that have overlap with resources already deployed in the account/region,
then the generated application will not be immediately deployable. If those overlapped resources are already managed by
another CloudFormation stack in that account/region, then those resources will need to be manually removed from the provided
template. Otherwise, if the overlapped resources are not managed by another CloudFormation stack, then first run remove those
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there some words missing here? I'm not sure what this part is supposed to say.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Github is highlighting too many lines. I'm asking about this part "Otherwise, if the overlapped resources are not managed by another CloudFormation stack, then first run remove those"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what the change should be here.

resources and deploy the template successfully, then re-add them and run `cdk import` to import them into your deployed stack.

### `cdk destroy`

Deletes a stack from it's environment. This will cause the resources in the stack to be destroyed (unless they were
Expand Down
Loading