Skip to content

Commit

Permalink
fix(core): cross stack references to string lists break (aws#22873)
Browse files Browse the repository at this point in the history
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*
  • Loading branch information
comcalvi authored and Brennan Ho committed Dec 9, 2022
1 parent 61de75d commit 2508509
Show file tree
Hide file tree
Showing 28 changed files with 1,675 additions and 47 deletions.
@@ -0,0 +1 @@
{"version":"22.0.0"}
@@ -0,0 +1,19 @@
{
"version": "22.0.0",
"files": {
"0fe7f73285a0ff152665f28743981914632b5c05b361126f8af577515c058bdc": {
"source": {
"path": "consumer.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "0fe7f73285a0ff152665f28743981914632b5c05b361126f8af577515c058bdc.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
}
},
"dockerImages": {}
}
@@ -0,0 +1,95 @@
{
"Resources": {
"GetAtt0B6ACA40": {
"Type": "AWS::SSM::Parameter",
"Properties": {
"Type": "StringList",
"Value": {
"Fn::Join": [
",",
{
"Fn::Split": [
"||",
{
"Fn::ImportValue": "producer:ExportsOutputFnGetAttendpointE7B9679BDnsEntries62080A34"
}
]
}
]
}
}
},
"Ref47C32AF2": {
"Type": "AWS::SSM::Parameter",
"Properties": {
"Type": "StringList",
"Value": {
"Fn::Join": [
",",
{
"Fn::Split": [
"||",
{
"Fn::ImportValue": "producer:ExportsOutputRefstringListParam77B646D6"
}
]
}
]
}
}
},
"ManualEB2ECD12": {
"Type": "AWS::SSM::Parameter",
"Properties": {
"Type": "StringList",
"Value": {
"Fn::Join": [
",",
{
"Fn::Split": [
"||",
{
"Fn::ImportValue": "ManualExport"
}
]
}
]
}
}
}
},
"Parameters": {
"BootstrapVersion": {
"Type": "AWS::SSM::Parameter::Value<String>",
"Default": "/cdk-bootstrap/hnb659fds/version",
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
}
},
"Rules": {
"CheckBootstrapVersion": {
"Assertions": [
{
"Assert": {
"Fn::Not": [
{
"Fn::Contains": [
[
"1",
"2",
"3",
"4",
"5"
],
{
"Ref": "BootstrapVersion"
}
]
}
]
},
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
}
]
}
}
}
@@ -0,0 +1,19 @@
{
"version": "22.0.0",
"files": {
"21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": {
"source": {
"path": "crossregionreferencesDefaultTestDeployAssertAB7415FD.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
}
},
"dockerImages": {}
}
@@ -0,0 +1,36 @@
{
"Parameters": {
"BootstrapVersion": {
"Type": "AWS::SSM::Parameter::Value<String>",
"Default": "/cdk-bootstrap/hnb659fds/version",
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
}
},
"Rules": {
"CheckBootstrapVersion": {
"Assertions": [
{
"Assert": {
"Fn::Not": [
{
"Fn::Contains": [
[
"1",
"2",
"3",
"4",
"5"
],
{
"Ref": "BootstrapVersion"
}
]
}
]
},
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
}
]
}
}
}
@@ -0,0 +1,14 @@
{
"version": "22.0.0",
"testCases": {
"cross-region-references/DefaultTest": {
"stacks": [
"producer",
"consumer"
],
"stackUpdateWorkflow": false,
"assertionStack": "cross-region-references/DefaultTest/DeployAssert",
"assertionStackName": "crossregionreferencesDefaultTestDeployAssertAB7415FD"
}
}
}

0 comments on commit 2508509

Please sign in to comment.