Skip to content

cli: support --import-existing-resources flag in cdk diff #32790

Open
@tmokmss

Description

@tmokmss

Describe the feature

Now that cdk deploy supports --import-existing-resources flag (#32676), cdk diff should support it as well.

Use Case

I want to know which resources are imported before deployment by just executing cdk diff.

Proposed Solution

Users should be able to just run cdk diff --import-existing-resources, and get a table of resources that will be imported.

CDK diff already supports displaying imported resources, so I guess all we need is to add a flag when calling createChangeset API here:

const changeSet = await options.cfn.createChangeSet({
StackName: options.stack.stackName,
ChangeSetName: options.changeSetName,
ChangeSetType: options.resourcesToImport ? 'IMPORT' : options.exists ? 'UPDATE' : 'CREATE',
Description: `CDK Changeset for diff ${options.uuid}`,
ClientToken: `diff${options.uuid}`,
TemplateURL: options.bodyParameter.TemplateURL,
TemplateBody: options.bodyParameter.TemplateBody,
Parameters: stackParams.apiParameters,
ResourcesToImport: options.resourcesToImport,
RoleARN: options.role,
Capabilities: ['CAPABILITY_IAM', 'CAPABILITY_NAMED_IAM', 'CAPABILITY_AUTO_EXPAND'],
});

Just like here:

const changeSet = await this.cfn.createChangeSet({
StackName: this.stackName,
ChangeSetName: changeSetName,
ChangeSetType: this.options.resourcesToImport ? 'IMPORT' : this.update ? 'UPDATE' : 'CREATE',
ResourcesToImport: this.options.resourcesToImport,
Description: `CDK Changeset for execution ${this.uuid}`,
ClientToken: `create${this.uuid}`,
ImportExistingResources: importExistingResources,
...this.commonPrepareOptions(),
});

Other Information

Currently it is possible to review the changeset before an actual deployment as described here, but it is not very handy.

Use the `--method=prepare-change-set` flag to review which resources are imported or not before deploying a changeset.
You can inspect the change set created by CDK from the management console or other external tools.
```console
$ cdk deploy --import-existing-resources --method=prepare-change-set
```

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

CDK version used

2.174.1

Environment details (OS name and version, etc.)

macOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/smallSmall work item – less than a day of effortfeature-requestA feature should be added or improved.p2package/toolsRelated to AWS CDK Tools or CLI

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions