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): floating list tokens synthesize to template #11899

Merged
merged 1 commit into from
Dec 7, 2020

Conversation

rix0rrr
Copy link
Contributor

@rix0rrr rix0rrr commented Dec 7, 2020

Encoded token lists are represented as ["#{Token[1234]}"] (as opposed
to encoded strings, which are represented as "${Token[1234]}", notice
the different sigil).

If a string that looks like "#{Token[...]}" ever appears outside
of a list context, that's an error. Someone got there by doing:

list[0]

Which we cannot allow, because things list list[n] are not detectable
by us and so cannot be adequately converted to CloudFormation syntax.

They are supposed to use Fn.select(n, list) instead.

We did not use to test for this, but of course people will do this
and then get confused about the results, so add an explicit test
and error message.

Closes #11750


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

Encoded token lists are represented as `["#{Token[1234]}"]` (as opposed
to encoded strings, which are represented as `"${Token[1234]}"`, notice
the different sigil).

If a string that looks like `"#{Token[...]}"` ever appears outside
of a list context, that's an error. Someone got there by doing:

```
list[0]
```

Which we cannot allow, because things list `list[n]` are not detectable
by us and so cannot be adequately converted to CloudFormation syntax.

They are supposed to use `Fn.select(n, list)` instead.

We did not use to test for this, but of course people *will* do this
and then get confused about the results, so add an explicit test
and error message.

Closes #11750
@rix0rrr rix0rrr requested a review from a team December 7, 2020 08:59
@rix0rrr rix0rrr self-assigned this Dec 7, 2020
@gitpod-io
Copy link

gitpod-io bot commented Dec 7, 2020

@github-actions github-actions bot added the @aws-cdk/core Related to core CDK functionality label Dec 7, 2020
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Dec 7, 2020
@mergify
Copy link
Contributor

mergify bot commented Dec 7, 2020

Thank you for contributing! Your pull request will be updated from master 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 60875a5 into master Dec 7, 2020
@mergify mergify bot deleted the huijbers/detect-floating-lists branch December 7, 2020 09:27
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: 99675e7
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

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

skiyani pushed a commit to skiyani/aws-cdk that referenced this pull request Dec 7, 2020
Encoded token lists are represented as `["#{Token[1234]}"]` (as opposed
to encoded strings, which are represented as `"${Token[1234]}"`, notice
the different sigil).

If a string that looks like `"#{Token[...]}"` ever appears outside
of a list context, that's an error. Someone got there by doing:

```
list[0]
```

Which we cannot allow, because things list `list[n]` are not detectable
by us and so cannot be adequately converted to CloudFormation syntax.

They are supposed to use `Fn.select(n, list)` instead.

We did not use to test for this, but of course people *will* do this
and then get confused about the results, so add an explicit test
and error message.

Closes aws#11750


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
rix0rrr added a commit that referenced this pull request Dec 12, 2020
…ime lists

Even though using `Vpc.fromVpcAttributes()` using deploy-time lists like
from `Fn.importValue()`s and `CfnParameters` was never really supposed
to work, it accidentally did.

The reason for that is:

```ts

// Encoded list token
const subnetIds = Token.asList(Fn.importValue('someValue'))
// [ '#{Token[1234]}' ]

// Gets parsed to a singleton `Subnet` list:
const subnets = subnetIds.map(s => Subnet.fromSubnetAttributes({ subnetId: s }));
// [ Subnet({ subnetId: '#{Token[1234]}' }) ]

// This 'subnetId' is illegal by itself, and if yould try to use it for,
// say, an ec2.Instance it would fail. However, if you treat this single
// subnet as a GROUP of subnets:
new CfnAutoScalingGroup({ subnetIds: subnets.map(s => s.subnetId) })
// [ '#{Token[1234]}' ]

// And this resolves back to:
resolve(cfnSubnetIds)
// SubnetIds: { Fn::ImportValue: 'someValue' }
```

--------

We introduced an additional check in #11899 to make sure that the
list-element token that represents an encoded list (`'#{Token[1234]}'`)
never occurs in a non-list context, because it's illegal there.

However, because:

* `Subnet.fromSubnetAttributes()` logs the subnetId as a *warning*
  to its own metadata (which will log a string like `"there's something
  wrong with '#{Token[1234]}' ..."`).
* All metadata is resolved just the same as the template expressions
  are.

The `resolve()` function encounters that orphaned list token in the
metadata and throws.

--------

The *proper* solution would be to handle unparseable list tokens
specially to never get into this situation, but doing that requires
introducing classes and new concepts that will be a large effort and
not be backwards compatible. Tracking in #4118.

Another possible solution is to stop resolving metadata. I don't
know if we usefully use this feature; I think we don't. However,
we have tests enforcing that it is being done, and I'm scared
to break something there.

The quick solution around this for now is to have
`Subnet.fromSubnetAttributes()` recognize when it's about to log
a problematic identifier to metadata, and don't do it.

Fixes #11945.
mergify bot pushed a commit that referenced this pull request Dec 14, 2020
…ime lists (#12040)

Even though using `Vpc.fromVpcAttributes()` using deploy-time lists like
from `Fn.importValue()`s and `CfnParameters` was never really supposed
to work, it accidentally did.

The reason for that is:

```ts

// Encoded list token
const subnetIds = Token.asList(Fn.importValue('someValue'))
// [ '#{Token[1234]}' ]

// Gets parsed to a singleton `Subnet` list:
const subnets = subnetIds.map(s => Subnet.fromSubnetAttributes({ subnetId: s }));
// [ Subnet({ subnetId: '#{Token[1234]}' }) ]

// This 'subnetId' is illegal by itself, and if yould try to use it for,
// say, an ec2.Instance it would fail. However, if you treat this single
// subnet as a GROUP of subnets:
new CfnAutoScalingGroup({ subnetIds: subnets.map(s => s.subnetId) })
// [ '#{Token[1234]}' ]

// And this resolves back to:
resolve(cfnSubnetIds)
// SubnetIds: { Fn::ImportValue: 'someValue' }
```

--------

We introduced an additional check in #11899 to make sure that the
list-element token that represents an encoded list (`'#{Token[1234]}'`)
never occurs in a non-list context, because it's illegal there.

However, because:

* `Subnet.fromSubnetAttributes()` logs the subnetId as a *warning*
  to its own metadata (which will log a string like `"there's something
  wrong with '#{Token[1234]}' ..."`).
* All metadata is resolved just the same as the template expressions
  are.

The `resolve()` function encounters that orphaned list token in the
metadata and throws.

--------

The *proper* solution would be to handle unparseable list tokens
specially to never get into this situation, but doing that requires
introducing classes and new concepts that will be a large effort and
not be backwards compatible. Tracking in #4118.

Another possible solution is to stop resolving metadata. I don't
know if we usefully use this feature; I think we don't. However,
we have tests enforcing that it is being done, and I'm scared
to break something there.

The quick solution around this for now is to have
`Subnet.fromSubnetAttributes()` recognize when it's about to log
a problematic identifier to metadata, and don't do it.

Fixes #11945.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
flochaz pushed a commit to flochaz/aws-cdk that referenced this pull request Jan 5, 2021
Encoded token lists are represented as `["#{Token[1234]}"]` (as opposed
to encoded strings, which are represented as `"${Token[1234]}"`, notice
the different sigil).

If a string that looks like `"#{Token[...]}"` ever appears outside
of a list context, that's an error. Someone got there by doing:

```
list[0]
```

Which we cannot allow, because things list `list[n]` are not detectable
by us and so cannot be adequately converted to CloudFormation syntax.

They are supposed to use `Fn.select(n, list)` instead.

We did not use to test for this, but of course people *will* do this
and then get confused about the results, so add an explicit test
and error message.

Closes aws#11750


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
flochaz pushed a commit to flochaz/aws-cdk that referenced this pull request Jan 5, 2021
…ime lists (aws#12040)

Even though using `Vpc.fromVpcAttributes()` using deploy-time lists like
from `Fn.importValue()`s and `CfnParameters` was never really supposed
to work, it accidentally did.

The reason for that is:

```ts

// Encoded list token
const subnetIds = Token.asList(Fn.importValue('someValue'))
// [ '#{Token[1234]}' ]

// Gets parsed to a singleton `Subnet` list:
const subnets = subnetIds.map(s => Subnet.fromSubnetAttributes({ subnetId: s }));
// [ Subnet({ subnetId: '#{Token[1234]}' }) ]

// This 'subnetId' is illegal by itself, and if yould try to use it for,
// say, an ec2.Instance it would fail. However, if you treat this single
// subnet as a GROUP of subnets:
new CfnAutoScalingGroup({ subnetIds: subnets.map(s => s.subnetId) })
// [ '#{Token[1234]}' ]

// And this resolves back to:
resolve(cfnSubnetIds)
// SubnetIds: { Fn::ImportValue: 'someValue' }
```

--------

We introduced an additional check in aws#11899 to make sure that the
list-element token that represents an encoded list (`'#{Token[1234]}'`)
never occurs in a non-list context, because it's illegal there.

However, because:

* `Subnet.fromSubnetAttributes()` logs the subnetId as a *warning*
  to its own metadata (which will log a string like `"there's something
  wrong with '#{Token[1234]}' ..."`).
* All metadata is resolved just the same as the template expressions
  are.

The `resolve()` function encounters that orphaned list token in the
metadata and throws.

--------

The *proper* solution would be to handle unparseable list tokens
specially to never get into this situation, but doing that requires
introducing classes and new concepts that will be a large effort and
not be backwards compatible. Tracking in aws#4118.

Another possible solution is to stop resolving metadata. I don't
know if we usefully use this feature; I think we don't. However,
we have tests enforcing that it is being done, and I'm scared
to break something there.

The quick solution around this for now is to have
`Subnet.fromSubnetAttributes()` recognize when it's about to log
a problematic identifier to metadata, and don't do it.

Fixes aws#11945.

----

*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
@aws-cdk/core Related to core CDK functionality contribution/core This is a PR that came from AWS.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(core): CfnParameter valueAsList -> List<String> is added as Token
3 participants