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(cdk): Resolve cross stack and default parameters for hotswaps #27195

Merged
merged 10 commits into from
Sep 28, 2023

Conversation

Amplifiyer
Copy link
Contributor

This PR solves two problems when doing hotswap deployments with nested stacks.

  1. Adding capabilities to evaluate CFN parameters of AWS::CloudFormation::Stack type (i.e. a nested stack). In this PR, we are only resolving Outputs section of AWS::CloudFormation::Stack and it can be expanded to other fields in the future. See https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/quickref-cloudformation.html#w2ab1c17c23c19b5 for CFN documentation around using Outputs ref parameters
  2. If a template has parameters with default values and they are not provided (a value) by the parent stack when invoking, then resolve these parameters using the default values in the template.

Partially helps #23533 and #25418


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

@aws-cdk-automation aws-cdk-automation requested a review from a team September 19, 2023 14:32
@github-actions github-actions bot added beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK p2 labels Sep 19, 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 Sep 19, 2023
@Amplifiyer Amplifiyer changed the title fix(aws-cdk): Resolve cross stack and default parameters for hotswaps fix(cdk): Resolve cross stack and default parameters for hotswaps Sep 19, 2023
@Amplifiyer Amplifiyer temporarily deployed to test-pipeline September 19, 2023 15:05 — with GitHub Actions Inactive
@comcalvi comcalvi self-assigned this Sep 20, 2023
Copy link
Contributor

@comcalvi comcalvi left a comment

Choose a reason for hiding this comment

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

I need to understand the addition of the sdk to an EvaluateCloudFormationTemplate before I can give this a better review.

account: this.account,
region: this.region,
partition: this.partition,
urlSuffix: this.urlSuffix,
listStackResources: listNestedStackResources,
sdk: this.sdk,
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we need this here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In current CDK, evaluate-cloudformation-template can only evaluate CFN (Intrinsic) Fn references for resources in the same stack (Let's call it A) and hence it is passed a list of A's resources to assist in evaluation.

However the problem comes when a resource in A stack references resources in a different stack (Let's call it B). In that case evaluate-cloudformation-template of A has no knowledge of it.

This PR refactors evaluate-cloudformation-template in a way that it can recursively instantiate another evaluate-cloudformation-template for the referenced stack. And to do that, A's evaluate-cloudformation-template needs to pass in the list of B's resources while creating another instance and hence the sdk needs to be passed in for the A's evaluate-cloudformation-template so that it can call B's listResources

Now, instead of having the caller to get the list of stack's resources and pass it to evaluate-cloudformation-template, it's better for evaluate-cloudformation-template to manage it on it's own, since these resources are specifically being used by the evaluate-cloudformation-template and instead just pass the sdk rather than both sdk and the stackResources

Comment on lines -57 to -60
// The current resources of the Stack.
// We need them to figure out the physical name of a resource in case it wasn't specified by the user.
// We fetch it lazily, to save a service call, in case all hotswapped resources have their physical names set.
const listStackResources = new LazyListStackResources(sdk, stackArtifact.stackName);
Copy link
Contributor

Choose a reason for hiding this comment

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

this has been moved elsewhere, could you explain why? I don't see why this is necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Answered here #27195 (comment)

@Amplifiyer Amplifiyer marked this pull request as ready for review September 21, 2023 18:17
Copy link
Contributor

@comcalvi comcalvi left a comment

Choose a reason for hiding this comment

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

Great work! This will merge soon, just need the integ tests to pass

@TheRealAmazonKendra
Copy link
Contributor

Apologies, I stopped the integ test progress on this because I thought it was a change I pushed. I've restarted it now.

@aws-cdk-automation
Copy link
Collaborator

➡️ PR build request submitted to test-main-pipeline ⬅️

A maintainer must now check the pipeline and add the pr-linter/cli-integ-tested label once the pipeline succeeds.

@TheRealAmazonKendra TheRealAmazonKendra added the pr-linter/cli-integ-tested Assert that any CLI changes have been integ tested label Sep 28, 2023
@aws-cdk-automation aws-cdk-automation removed the pr/needs-cli-test-run This PR needs CLI tests run against it. label Sep 28, 2023
@comcalvi comcalvi added the pr-linter/exempt-integ-test The PR linter will not require integ test changes label Sep 28, 2023
@aws-cdk-automation aws-cdk-automation dismissed their stale review September 28, 2023 16:54

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

@mergify
Copy link
Contributor

mergify bot commented Sep 28, 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: 638bf31
  • 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 3507141 into aws:main Sep 28, 2023
8 of 9 checks passed
@mergify
Copy link
Contributor

mergify bot commented Sep 28, 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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK 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.

4 participants