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(cfn-include): fix issues in Conditions handling #9142

Merged
merged 1 commit into from
Jul 17, 2020

Conversation

skinny85
Copy link
Contributor

The current Conditions handling in cloudformation-include has a few flaws,
that are all corrected in this change:

  • Do not fail when a Condition and a Resource share the same logical ID
  • Handle changing the logical IDs of Conditions used in Fn::If expressions
  • Handle changing the logical IDs of Conditions referenced inside the Conditions section
  • Do not fail when referring to a Parameter from inside a Condition

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 comcalvi July 17, 2020 19:10
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Jul 17, 2020
@skinny85 skinny85 self-assigned this Jul 17, 2020
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.

Nicely done! Just a few minor points.

Comment on lines 265 to 267
throw new Error(`Output with name '${logicalId}' refers to a Condition with name\
'${outputAttributes.Condition}' which was not found in this template`);
throw new Error(`Output with name '${logicalId}' refers to a Condition with name '${outputAttributes.Condition}' which was not found in this template`);
Copy link
Contributor

Choose a reason for hiding this comment

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

why remove the line break 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.

Because the unindented code on line 266 screws up the vertical guides in my IDE. I'll do it in a different way though.

@@ -251,6 +251,41 @@ describe('CDK Include', () => {
);
});

test('correctly change references to Conditions when renaming them', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I like the handling of two cases with one test here, nicely done.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks 🙂

}

const self = this;
const cfnParser = new cfn_parse.CfnParser({
finder: {
findResource() { throw new Error('Using GetAtt in Condition definitions is not allowed'); },
Copy link
Contributor

Choose a reason for hiding this comment

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

We still don't have a unit test that hits this case

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right. Will add.

const cfnCondition = new core.CfnCondition(this.conditionsScope, conditionName, {
expression: cfnParser.parseValue(this.template.Conditions[conditionName]),
});

// ToDo handle renaming of the logical IDs of the conditions
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't think we still need this ToDo

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's basically for checking the value of this.preserveLogicalIds, which today is always true. Just a reminder to change here once that's no longer the case 🙂.

The current Conditions handling in cloudformation-include has a few flaws,
that are all corrected in this change:

- Do not fail when a Condition and a Resource share the same logical ID
- Handle changing the logical IDs of Conditions used in Fn::If expressions
- Handle changing the logical IDs of Conditions referenced inside the Conditions section
- Do not fail when referring to a Parameter from inside a Condition
@skinny85 skinny85 force-pushed the fix/cfn-include-conditions branch from 27a9961 to aa62448 Compare July 17, 2020 22:15
@skinny85 skinny85 requested a review from comcalvi July 17, 2020 22:15
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

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

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

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.

LGTM!

@mergify
Copy link
Contributor

mergify bot commented Jul 17, 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 e8d0776 into aws:master Jul 17, 2020
@skinny85 skinny85 deleted the fix/cfn-include-conditions branch July 17, 2020 23:58
curtiseppel pushed a commit to curtiseppel/aws-cdk that referenced this pull request Aug 11, 2020
The current Conditions handling in cloudformation-include has a few flaws,
that are all corrected in this change:

- Do not fail when a Condition and a Resource share the same logical ID
- Handle changing the logical IDs of Conditions used in Fn::If expressions
- Handle changing the logical IDs of Conditions referenced inside the Conditions section
- Do not fail when referring to a Parameter from inside a Condition

----

*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.

3 participants