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(pipelines): undeployable due to dependency cycle #18686

Merged
merged 11 commits into from
Jan 28, 2022
Merged

Conversation

rix0rrr
Copy link
Contributor

@rix0rrr rix0rrr commented Jan 27, 2022

A dependency cycle was inadvertently introduced to CDK Pipelines in #18492.

Fix that dependency cycle, and also one in Cognito IdentityPools.

Add facilities to the assertions library to automatically detect this in the future,
to stop errors like this from slipping in.

We could make it a separate assertion method
(Template.fromStack().assertNoCycles()), but the only thing that will
do is give you an opportunity to forget to put the test in.

Instead, we just check it by default for every generated template.

Fixes #18673.


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

We happily generate templates with dependency cycles. Those would be
undeployable in CloudFormation, so we should make it impossible that
templates like these pass unit test validation.

We could make it a separate assertion method
(`Template.fromStack().assertNoCycles()`), but the only thing that will
do is give you an opportunity to forget to put the test in.

Instead, we just check it by default for every generated template.
@rix0rrr rix0rrr requested a review from a team January 27, 2022 11:10
@rix0rrr rix0rrr self-assigned this Jan 27, 2022
@gitpod-io
Copy link

gitpod-io bot commented Jan 27, 2022

@github-actions github-actions bot added the @aws-cdk/assertions Related to the @aws-cdk/assertv2 package label Jan 27, 2022
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Jan 27, 2022
@rix0rrr rix0rrr changed the title fix: dependency cycles fix(assertions): dependency cycles are not detected Jan 27, 2022
@rix0rrr rix0rrr changed the title fix(assertions): dependency cycles are not detected fix(pipelines): undeployable due to dependency cycle Jan 28, 2022
@@ -1084,6 +1084,25 @@ describe('Template', () => {
expect(Object.keys(result).length).toEqual(0);
});
});

test('throws when given a templat with cyclic dependencies', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

*template

// Don't know why this was added in the first place, but I'm disabling it for now and if
// no complaints come from this, we're probably safe to remove it altogether.
// attachment.node.addDependency(this);
Array.isArray(attachment);
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 prevents an "unused variable" error :)

@mergify
Copy link
Contributor

mergify bot commented Jan 28, 2022

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

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject89A8053A-LhjRyN9kxr8o
  • Commit ID: 6dd81c7
  • 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 009d689 into master Jan 28, 2022
@mergify mergify bot deleted the huijbers/dep-cycle branch January 28, 2022 17:13
@mergify
Copy link
Contributor

mergify bot commented Jan 28, 2022

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

Comment on lines +3 to +9
/**
* Check a template for cyclic dependencies
*
* This will make sure that we don't happily validate templates
* in unit tests that wouldn't deploy to CloudFormation anyway.
*/
export function checkTemplateForCyclicDependencies(template: Template): void {
Copy link
Contributor

Choose a reason for hiding this comment

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

So cool! 🎉

TikiTDO pushed a commit to TikiTDO/aws-cdk that referenced this pull request Feb 21, 2022
A dependency cycle was inadvertently introduced to CDK Pipelines in aws#18492.

Fix that dependency cycle, and also one in Cognito IdentityPools.

Add facilities to the `assertions` library to automatically detect this in the future,
to stop errors like this from slipping in.

We could make it a separate assertion method
(`Template.fromStack().assertNoCycles()`), but the only thing that will
do is give you an opportunity to forget to put the test in.

Instead, we just check it by default for every generated template.

Fixes aws#18673.


----

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

Successfully merging this pull request may close these issues.

CDK Pipelines: Circular dependency on initial CDK Deploy
6 participants