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): allow override with cross-stack references #23382

Closed
wants to merge 4 commits into from

Conversation

tmokmss
Copy link
Contributor

@tmokmss tmokmss commented Dec 17, 2022

closes #18882

Below is what I found as the root cause and how it can be fixed. I confirmed all the unit tests are passing.


Previously when we used a cross-stack reference in override, it was not resolved as an Fn::ImportValue.

To make it an Fn::ImportValue, we need to get every token in an app and find references (tokens that references resources outside of its stack) from them. The related code is here:

function findAllReferences(root: IConstruct) {
const result = new Array<{ source: CfnElement, value: CfnReference }>();

To get all the tokens in an app, we use RememberingTokenResolver, which remembers every token it has found during resolution. So basically this resolver must be used on every resolution to find all the tokens.

export class RememberingTokenResolver extends DefaultTokenResolver {
private readonly tokensSeen = new Set<IResolvable>();
public resolveToken(t: IResolvable, context: IResolveContext, postProcessor: IPostProcessor) {
this.tokensSeen.add(t);
return super.resolveToken(t, context, postProcessor);
}

However, the resolver is not used specifically when we resolve tokens in raw overrides. Actually the current interface of postProcess function of PostResolveToken class makes It difficult to use an external resolver.

const resolvedRawOverrides = Tokenization.resolve(this.rawOverrides, {
scope: this,
resolver: CLOUDFORMATION_TOKEN_RESOLVER,
// we need to preserve the empty elements here,
// as that's how removing overrides are represented as
removeEmpty: false,
});

That is why, in this PR, we move the resolution process outside of the postProcess, allowing to resolve tokens in raw overrides with the RememberingTokenResolver resolver.

This change also simplifies the current implementation of deepMerge.

Related PRs: #15018 #20608 #22294

Note: Now the removeEmpty flag introduced by #15018 is not used by any internal code and can be removed. However, we cannot remove it immediately since it is a public API. Maybe we can just deprecate and remove it in a future version.


All Submissions:

Adding new Construct Runtime Dependencies:

  • This PR adds new construct runtime 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

@tmokmss tmokmss marked this pull request as draft December 17, 2022 17:39
@gitpod-io
Copy link

gitpod-io bot commented Dec 17, 2022

@aws-cdk-automation aws-cdk-automation requested a review from a team December 17, 2022 17:40
@github-actions github-actions bot added p2 admired-contributor [Pilot] contributed between 13-24 PRs to the CDK labels Dec 17, 2022
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.

@tmokmss tmokmss changed the title draft: fix cross stack override fix(core): allow override with cross-stack references Dec 17, 2022
@github-actions github-actions bot added bug This issue is a bug. p1 and removed p2 labels Dec 17, 2022
@tmokmss tmokmss marked this pull request as ready for review December 17, 2022 19:27
@tmokmss
Copy link
Contributor Author

tmokmss commented Dec 22, 2022

I don't think we need to change or add an integration test for this fix. It's ready for review :)

@aws-cdk-automation
Copy link
Collaborator

This PR has been in the CHANGES REQUESTED state for 3 weeks, and looks abandoned. To keep this PR from being closed, please continue work on it. If not, it will automatically be closed in a week.

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

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

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

@aws-cdk-automation
Copy link
Collaborator

This PR has been deemed to be abandoned, and will be automatically closed. Please create a new PR for these changes if you think this decision has been made in error.

@aws-cdk-automation aws-cdk-automation added the closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. label Jan 16, 2023
@tmokmss
Copy link
Contributor Author

tmokmss commented Jan 18, 2023

Hi @corymhall, could you take a look at this when you get a chance? I saw you recently worked on some related PRs. Or at least It'd be great if you could reopen and add exempt-integ-test label to this :)

@comcalvi comcalvi reopened this Jan 26, 2023
@aws-cdk-automation
Copy link
Collaborator

This PR has been deemed to be abandoned, and will be automatically closed. Please create a new PR for these changes if you think this decision has been made in error.

@tmokmss
Copy link
Contributor Author

tmokmss commented Jan 30, 2023

Hi @comcalvi, thank you for the attention! Could you check it again? I think it needs an exempt-integ-test label.

@aws-cdk-automation
Copy link
Collaborator

The pull request linter fails with the following errors:

❌ Fixes must contain a change to an integration test file and the resulting snapshot.

PRs must pass status checks before we can provide a meaningful review.

If you would like to request an exemption from the status checks or clarification on feedback, please leave a comment on this PR containing Exemption Request and/or Clarification Request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
admired-contributor [Pilot] contributed between 13-24 PRs to the CDK bug This issue is a bug. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. p1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PropertyOverrides: Tokens not properly resolved in cross stack scenarios when using property overrides
3 participants