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): CFN version and description template sections were merged incorrectly #8251

Merged
merged 1 commit into from
Jun 2, 2020

Conversation

skinny85
Copy link
Contributor

In the merge logic in Stack when rendering the template,
it was mistakenly assumed that all CFN sections are objects.
However, there are some sections, like Description and AWSTemplateFormatVersion,
that are in fact strings.
Add special logic for those cases in the merge functionality
(multiple provided CFN versions are checked for being identical,
and multiple descriptions are merged together, with a newline in between).

Fixes #8151


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

@skinny85 skinny85 requested a review from rix0rrr May 28, 2020 01:24
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label May 28, 2020
@skinny85 skinny85 self-assigned this May 28, 2020
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

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

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

Comment on lines 863 to 866
case 'Description':
// merge the two descriptions, with a newline in between
template[section] = `${dest}\n${src}`;
break;
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a weird choice. I would say either error or destination wins.

In the case of CfnInclude, I think it's fair to say that if the description was altered after import, the altered description wins.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not about "altering" - this is the case when Description was provided from multiple places. See the test for this:

    new CfnInclude(stack, 'T1', {
      template: {
        AWSTemplateFormatVersion: '2010-09-09',
        Description: 'Test 1',
      },
    });
    new CfnInclude(stack, 'T2', {
      template: {
        AWSTemplateFormatVersion: '2010-09-09',
        Description: 'Test 2',
      },
    });

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.

Approving but with the strong request to apply a light refactor and include validation.

packages/@aws-cdk/core/lib/stack.ts Outdated Show resolved Hide resolved
@rix0rrr rix0rrr added the pr/do-not-merge This PR should not be merged at this time. label May 29, 2020
…incorrectly

In the merge logic in Stack when rendering the template,
it was mistakenly assumed that all CFN sections are objects.
However, there are some sections, like Description and AWSTemplateFormatVersion,
that are in fact strings.
Add special logic for those cases in the merge functionality
(multiple provided CFN versions are checked for being identical,
and mutliple descriptions are merged together, with a newline in between).

Fixes aws#8151
@skinny85 skinny85 force-pushed the fix/stacks-merge-template-sections branch from b084416 to f009d29 Compare June 2, 2020 01:12
@skinny85 skinny85 removed the pr/do-not-merge This PR should not be merged at this time. label Jun 2, 2020
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

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

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

@skinny85 skinny85 merged commit b7e328d into aws:master Jun 2, 2020
@skinny85 skinny85 deleted the fix/stacks-merge-template-sections branch June 2, 2020 02:12
skinny85 added a commit to skinny85/aws-cdk that referenced this pull request Aug 6, 2020
When we changed the merging behavior in aws#8251,
we forgot to account for the 'Rules' section.
To prevent that error from happening again,
let's default to merging objects without duplicates.

Fixes aws#9485
skinny85 added a commit to skinny85/aws-cdk that referenced this pull request Aug 7, 2020
When we changed the merging behavior in aws#8251,
we forgot to account for the 'Rules' section.
To prevent that error from happening again,
let's default to merging objects without duplicates.

Fixes aws#9485
mergify bot pushed a commit that referenced this pull request Aug 7, 2020
When we changed the merging behavior in #8251,
we forgot to account for the 'Rules' section.
To prevent that error from happening again,
let's default to merging objects without duplicates.

Fixes #9485

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
skinny85 added a commit to skinny85/aws-cdk that referenced this pull request Aug 8, 2020
When we changed the merging behavior in aws#8251,
we forgot to account for the 'Rules' section.
To prevent that error from happening again,
let's default to merging objects without duplicates.

Fixes aws#9485
eladb pushed a commit that referenced this pull request Aug 10, 2020
When we changed the merging behavior in #8251,
we forgot to account for the 'Rules' section.
To prevent that error from happening again,
let's default to merging objects without duplicates.

Fixes #9485

----

*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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Multiple instances of CfnInclude cause TypeError
4 participants