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(core): cross stack references to string lists break #22873

Merged
merged 38 commits into from
Dec 8, 2022

Conversation

comcalvi
Copy link
Contributor

@comcalvi comcalvi commented Nov 11, 2022

Previously only strings could be referenced across stacks, due to a CloudFormation requirement that all Outputs evaluate to strings. This PR allows string lists to be referenced across stacks, like VpcEndpoint DnsEntries, by wrapping the exports / imports in Fn::Splits and Fn::Joins. This does not work across environments.

This also makes ssm.StringListParameter use Fn.split(value) instead of value.split().

This is part of the fix to #21682. Cross-env support will be added in a future PR.

Adds a new public method, exportListValue(), to the Stack class to avoid breaking changes.

Implementation requires adding type hints to IResolvable and modifying the codegen to populate them correctly.


All Submissions:

Adding new Unconventional Dependencies:

  • This PR adds new unconventional dependencies following the process described here

New Features

  • Have you added the new feature to an integration test?
    • Did you use yarn integ to deploy the infrastructure and generate the snapshot (i.e. yarn integ without --dry-run)?

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

@gitpod-io
Copy link

gitpod-io bot commented Nov 11, 2022

@aws-cdk-automation aws-cdk-automation requested a review from a team November 11, 2022 00:11
@github-actions github-actions bot added the p2 label Nov 11, 2022
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Nov 11, 2022
@comcalvi comcalvi changed the title fix(core): cross stack references to string lists fix(core): cross stack references to string lists break Nov 14, 2022
packages/@aws-cdk/aws-ssm/lib/parameter.ts Show resolved Hide resolved
packages/@aws-cdk/core/lib/private/refs.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/core/lib/stack.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/core/lib/stack.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/core/lib/stack.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/core/lib/stack.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/core/test/stack.test.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/core/lib/stack.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/core/lib/stack.ts Outdated Show resolved Hide resolved
@aws-cdk-automation aws-cdk-automation dismissed their stale review December 2, 2022 18:55

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

@rix0rrr rix0rrr added the pr/do-not-merge This PR should not be merged at this time. label Dec 6, 2022
Copy link
Contributor

@rix0rrr rix0rrr left a comment

Choose a reason for hiding this comment

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

Some polishing but conditionally approved

Comment on lines +54 to +57
} else if (Array.isArray(props.value)) {
// `props.value` is a string, but because cross-stack exports allow passing any,
// we need to check for lists here.
throw new Error(`CloudFormation output was given a string list instead of a string at path "${this.node.path}"`);
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this definitely fail in CloudFormation, or does it implicitly join or something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it definitely fails

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Template format error: The Value field of every Outputs member must evaluate to a String.


const importExpr = exportingStack.exportValue(reference);
if (Array.isArray((exportingStack as any).determineImportValue(reference))) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this not the moment where we would inspect the type hint of reference ?

Comment on lines +1030 to +1032
if (Array.isArray(importValue)) {
throw new Error('Attempted to export a list value from `exportValue()`: use `exportStringListValue()` instead');
}
Copy link
Contributor

Choose a reason for hiding this comment

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

For some reason this makes me uneasy. Can you do inspections on the value's type and type hints, before we go to export it, instead?

Comment on lines 1067 to 1070
const importValue = this.determineImportValue(exportedValue);

if (!Array.isArray(importValue)) {
throw new Error('Attempted to export a string value from `exportStringListValue()`: use `exportValue()` instead');
Copy link
Contributor

Choose a reason for hiding this comment

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

For some reason this makes me uneasy. Can you do inspections on the value's type and type hints, before we go to export it, instead?

@comcalvi comcalvi removed the pr/do-not-merge This PR should not be merged at this time. label Dec 6, 2022
@mergify
Copy link
Contributor

mergify bot commented Dec 6, 2022

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).

@mergify
Copy link
Contributor

mergify bot commented Dec 7, 2022

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).

1 similar comment
@mergify
Copy link
Contributor

mergify bot commented Dec 7, 2022

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).

@TheRealAmazonKendra
Copy link
Contributor

@Mergifyio requeue

@mergify
Copy link
Contributor

mergify bot commented Dec 7, 2022

requeue

✅ The queue state of this pull request has been cleaned. It can be re-embarked automatically

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

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

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

@mergify
Copy link
Contributor

mergify bot commented Dec 8, 2022

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).

@mergify mergify bot merged commit 3ddb8cf into aws:main Dec 8, 2022
brennanho pushed a commit to brennanho/aws-cdk that referenced this pull request Dec 9, 2022
Previously only strings could be referenced across stacks, due to a CloudFormation requirement that all `Output`s evaluate to strings. This PR allows string lists to be referenced across stacks, like [VpcEndpoint DnsEntries](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-vpcendpoint.html#aws-resource-ec2-vpcendpoint-return-values), by wrapping the exports / imports in `Fn::Split`s and `Fn::Join`s. This does not work across environments.

This also makes `ssm.StringListParameter` use `Fn.split(value)` instead of `value.split()`.

This is part of the fix to aws#21682. Cross-env support will be added in a future PR.

Adds a new public method, `exportListValue()`, to the `Stack` class to avoid breaking changes.

Implementation requires adding type hints to `IResolvable` and modifying the codegen to populate them correctly.


----

### All Submissions:

* [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [x] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)?
	* [x] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
brennanho pushed a commit to brennanho/aws-cdk that referenced this pull request Jan 20, 2023
Previously only strings could be referenced across stacks, due to a CloudFormation requirement that all `Output`s evaluate to strings. This PR allows string lists to be referenced across stacks, like [VpcEndpoint DnsEntries](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-vpcendpoint.html#aws-resource-ec2-vpcendpoint-return-values), by wrapping the exports / imports in `Fn::Split`s and `Fn::Join`s. This does not work across environments.

This also makes `ssm.StringListParameter` use `Fn.split(value)` instead of `value.split()`.

This is part of the fix to aws#21682. Cross-env support will be added in a future PR.

Adds a new public method, `exportListValue()`, to the `Stack` class to avoid breaking changes.

Implementation requires adding type hints to `IResolvable` and modifying the codegen to populate them correctly.


----

### All Submissions:

* [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [x] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)?
	* [x] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
brennanho pushed a commit to brennanho/aws-cdk that referenced this pull request Feb 22, 2023
Previously only strings could be referenced across stacks, due to a CloudFormation requirement that all `Output`s evaluate to strings. This PR allows string lists to be referenced across stacks, like [VpcEndpoint DnsEntries](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-vpcendpoint.html#aws-resource-ec2-vpcendpoint-return-values), by wrapping the exports / imports in `Fn::Split`s and `Fn::Join`s. This does not work across environments.

This also makes `ssm.StringListParameter` use `Fn.split(value)` instead of `value.split()`.

This is part of the fix to aws#21682. Cross-env support will be added in a future PR.

Adds a new public method, `exportListValue()`, to the `Stack` class to avoid breaking changes.

Implementation requires adding type hints to `IResolvable` and modifying the codegen to populate them correctly.


----

### All Submissions:

* [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [x] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)?
	* [x] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)?

*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
contribution/core This is a PR that came from AWS. p2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants