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

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

Open
1 of 2 tasks
tmokmss opened this issue Jan 8, 2025 · 4 comments · May be fixed by #32831
Open
1 of 2 tasks

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

tmokmss opened this issue Jan 8, 2025 · 4 comments · May be fixed by #32831
Labels
effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2 package/tools Related to AWS CDK Tools or CLI

Comments

@tmokmss
Copy link
Contributor

tmokmss commented Jan 8, 2025

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

@tmokmss tmokmss added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Jan 8, 2025
@github-actions github-actions bot added the package/tools Related to AWS CDK Tools or CLI label Jan 8, 2025
@ashishdhingra ashishdhingra self-assigned this Jan 8, 2025
@ashishdhingra ashishdhingra added p2 investigating This issue is being investigated and/or work is in progress to resolve the issue. and removed needs-triage This issue or PR still needs to be triaged. labels Jan 8, 2025
@ashishdhingra
Copy link
Contributor

CDK diff is one of the prior step for CDK deploy. Hence, for cdk diff only operation, it makes sense to support --import-existing-resources flag.

@ashishdhingra ashishdhingra added effort/small Small work item – less than a day of effort and removed investigating This issue is being investigated and/or work is in progress to resolve the issue. labels Jan 8, 2025
@ashishdhingra ashishdhingra removed their assignment Jan 8, 2025
@tmokmss
Copy link
Contributor Author

tmokmss commented Jan 9, 2025

Hi @kaizencc, thank you for the last PR of cdk deploy!
I'm willing to add this feature, but it seems cdk cli is getting a huge change #32775. Should I wait for the diversion to complete, or is it okay to start to work on the issue immediately?

@rix0rrr
Copy link
Contributor

rix0rrr commented Jan 9, 2025

Depends on how long you think it will take. But I don't think our reorganization is worth blocking any interesting ongoing work on.

Yes, it will be some work to transplant a PR if it happens to not land before the split happens... but that's not insurmountable, it's just a bit of drudgery (and probably not even too bad).

I would just start if I were you.

@tmokmss
Copy link
Contributor Author

tmokmss commented Jan 9, 2025

Thanks @rix0rrr for clarification! I'll start to work on this now then :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2 package/tools Related to AWS CDK Tools or CLI
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants