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

fix(cli): cannot cdk import resources with multiple identifiers #24439

Merged
merged 7 commits into from
Mar 6, 2023

Conversation

rix0rrr
Copy link
Contributor

@rix0rrr rix0rrr commented Mar 3, 2023

When CloudFormation tells us about identifiers for resources it can import, it returns a string[].

Our CLI used to interpret this as a set of identifiers that all must be present. Instead, the contract is actually: each string is a comma-separated list of identifiers that must be present together, but from all strings exactly one key combination should be supplied (and not multiple).

So:

  • ['BucketName'] -> Supply BucketName (easy)
  • ['TableName', 'TableArn'] -> supply exactly one of TableName or TableArn (but not both)
  • ['HostedZoneId,Name'] -> supply BOTH HostedZoneId and Name.

Because of our misinterpretations, both the cases of resources with multiple POSSIBLE identifiers as well as multiple REQUIRED identifiers would fail to import.

Make the code correctly model the expect types: identifiers are a string[][], where the outer array indicates OR and the inner array indicates AND.

  • For any of the combinations of properties we can lift from the template, prompt the user to confirm (typically 0 or 1, might be more). If the user rejected any of them, we don't do the resource at all.
  • If we couldn't lift any full key from the template, ask the user for the properties of each compound key, lifting parts of it from the template if possible.

Fixes #20895.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

Some resources that can be imported by CloudFormation allow multiple
identifiers. For example, `AWS::DynamoDB::GlobalTable` allows
`TableName`, `TableArn`, and `TableStreamArn`.

The CLI used to interpret multiple identifiers as "all must be present",
but the contract is actually "exactly one must be present":

* CloudFormation would fail the import if you supply all the fields;
* but CDK would skip the import if you left one out.

The effect is that it is impossible to import resources that allow
more than one identifier.

Fix this by being satisfied as soon as we have one identifier from
the set, instead of expecting all of them to be filled.

Fixes #20895.
@rix0rrr rix0rrr requested a review from a team March 3, 2023 11:25
@rix0rrr rix0rrr self-assigned this Mar 3, 2023
@aws-cdk-automation aws-cdk-automation requested a review from a team March 3, 2023 11:25
@github-actions github-actions bot added bug This issue is a bug. p2 labels Mar 3, 2023
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Mar 3, 2023
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

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

The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.

A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed add Clarification Request to a comment.

@aws-cdk-automation aws-cdk-automation added the pr/needs-cli-test-run This PR needs CLI tests run against it. label Mar 3, 2023
@rix0rrr rix0rrr added pr-linter/exempt-integ-test The PR linter will not require integ test changes pr/do-not-merge This PR should not be merged at this time. labels Mar 3, 2023
@rix0rrr
Copy link
Contributor Author

rix0rrr commented Mar 3, 2023

Ah the reality is slightly more complicated.

ResourceIdentifiers can return ["A", "B", "C,D"], where C,D DO need to be provided together.

@rix0rrr rix0rrr changed the title fix(cli): cannot cdk import resources that allow multiple identifiers fix(cli): cannot cdk import resources with multiple identifiers Mar 3, 2023
@rix0rrr rix0rrr removed the pr/do-not-merge This PR should not be merged at this time. label Mar 3, 2023
@rix0rrr rix0rrr added the pr-linter/cli-integ-tested Assert that any CLI changes have been integ tested label Mar 6, 2023
@aws-cdk-automation aws-cdk-automation dismissed their stale review March 6, 2023 11:09

✅ Updated pull request passes all PRLinter validations. Dissmissing previous PRLinter review.

@aws-cdk-automation aws-cdk-automation removed the pr/needs-cli-test-run This PR needs CLI tests run against it. label Mar 6, 2023
@mergify
Copy link
Contributor

mergify bot commented Mar 6, 2023

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: c3b56b1
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit a70ff1a into main Mar 6, 2023
@mergify mergify bot deleted the huijbers/cdk-import-multi branch March 6, 2023 12:00
@mergify
Copy link
Contributor

mergify bot commented Mar 6, 2023

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

homakk pushed a commit to homakk/aws-cdk that referenced this pull request Mar 28, 2023
…s#24439)

When CloudFormation tells us about identifiers for resources it can import, it returns a `string[]`.

Our CLI used to interpret this as a set of identifiers that all must be present. Instead, the contract is actually: each `string` is a comma-separated list of identifiers that must be present together, but from all `strings` exactly one key combination should be supplied (and not multiple).

So:

* `['BucketName']` -> Supply BucketName (easy)
* `['TableName', 'TableArn']` -> supply exactly one of TableName or TableArn (but not both)
* `['HostedZoneId,Name']` -> supply BOTH HostedZoneId and Name.

Because of our misinterpretations, both the cases of resources with multiple POSSIBLE identifiers as well as multiple REQUIRED identifiers would fail to import.

Make the code correctly model the expect types: identifiers are a `string[][]`, where the outer array indicates `OR` and the inner array indicates `AND`.

* For any of the combinations of properties we can lift from the template, prompt the user to confirm (typically 0 or 1, might be more). If the user rejected any of them, we don't do the resource at all.
* If we couldn't lift any full key from the template, ask the user for the properties of each compound key, lifting parts of it from the template if possible.

Fixes aws#20895.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. contribution/core This is a PR that came from AWS. p2 pr-linter/cli-integ-tested Assert that any CLI changes have been integ tested pr-linter/exempt-integ-test The PR linter will not require integ test changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

import: asks for multiple resource identifiers at once
3 participants