Creating a codepipeline.Pipeline with a codebuild.PipelineProject in a different stack results in a circular reference
See original GitHub issueNote: for support questions, please first reference our documentation, then use Stackoverflow. This repository’s issues are intended for feature requests and bug reports.
-
I’m submitting a …
- 🪲 bug report
-
What is the current behavior? If the current behavior is a 🪲bug🪲: Please provide the steps to reproduce
I am trying to follow the example on this feature https://github.com/aws/aws-cdk/pull/1924 to create a codepipeline with codebuild actions that are created in a separate stack. When I do, I get this error:
Error: 'BuildStack' depends on 'PipelineStack' (BuildStack/CodeBuildProject/Role/DefaultPolicy/Resource -> PipelineStack/Pipeline/ArtifactsBucket/Resource.Arn). Adding this dependency (PipelineStack/Pipeline/ArtifactsBucketEncryptionKey/Resource -> BuildStack/CodeBuildProject/Role/Resource.Arn) would create a cyclic reference.
Here is my sample code that I am working with
#!/usr/bin/env node
import 'source-map-support/register';
import cdk = require('@aws-cdk/core');
import commit = require('@aws-cdk/aws-codecommit');
import pipeline = require('@aws-cdk/aws-codepipeline');
import pipeline_actions = require('@aws-cdk/aws-codepipeline-actions');
import codebuild = require ('@aws-cdk/aws-codebuild');
const region = 'us-east-2';
const account = '12345678';
const app = new cdk.App();
const pipelineStack = new cdk.Stack(app, `PipelineStack`, {
env: {
account: account,
region: region
}
});
const repo = new commit.Repository(pipelineStack, 'Repo', {
repositoryName: 'test'
});
const sourceOutput = new pipeline.Artifact();
const sourceAction = new pipeline_actions.CodeCommitSourceAction({
actionName: 'CodeCommit',
repository: repo,
output: sourceOutput,
branch: 'master'
});
const codePipeline = new pipeline.Pipeline(pipelineStack, 'Pipeline', {
pipelineName: 'test',
stages: [
{
stageName: 'Source',
actions: [sourceAction],
}
],
});
const buildStack = new cdk.Stack(app, `BuildStack`, {
env: {
account: account,
region: region
}
});
const buildProject = new codebuild.PipelineProject(buildStack, 'CodeBuildProject', {
projectName: 'test-build',
});
const buildAction = new pipeline_actions.CodeBuildAction({
project: buildProject,
actionName: 'CodeBuild',
input: sourceOutput,
});
codePipeline.addStage({
stageName: `Deploy-Environment`,
actions: [buildAction]
});
- What is the expected behavior (or behavior of feature suggested)?
Based off the feature https://github.com/aws/aws-cdk/pull/1924, I would expect to be able to create a codepipeline in one stack and then add a codebuild project created in a separate stack as a stage. Currently I am trying everything within the same account.
- What is the motivation / use case for changing the behavior or adding this feature?
The use case is to be able to create a codepipeline in one account with build/deploy actions in a separate account. Most of the motivation is described in the feature https://github.com/aws/aws-cdk/pull/1924
-
Please tell us about your environment:
- CDK CLI Version: 1.0.0
- Module Version: 1.0.0
- OS: [OSX Mojave ]
- Language: [TypeScript ]
-
Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. associated pull-request, stackoverflow, gitter, etc)
Full error:
/Users/user/cdk/demo/node_modules/@aws-cdk/core/lib/stack.ts:272
throw new Error(`'${stack.node.path}' depends on '${this.node.path}' (${dep.join(', ')}). Adding this dependency (${reason}) would create a cyclic reference.`);
^
Error: 'BuildStack' depends on 'PipelineStack' (BuildStack/CodeBuildProject/Role/DefaultPolicy/Resource -> PipelineStack/Pipeline/ArtifactsBucket/Resource.Arn). Adding this dependency (PipelineStack/Pipeline/ArtifactsBucketEncryptionKey/Resource -> BuildStack/CodeBuildProject/Role/Resource.Arn) would create a cyclic reference.
at Stack.addDependency (/Users/user/cdk/demo/node_modules/@aws-cdk/core/lib/stack.ts:272:15)
at CfnReference.consumeFromStack (/Users/user/cdk/demo/node_modules/@aws-cdk/core/lib/private/cfn-reference.ts:125:22)
at Stack.prepare (/Users/user/cdk/demo/node_modules/@aws-cdk/core/lib/stack.ts:489:23)
at Function.prepare (/Users/user/cdk/demo/node_modules/@aws-cdk/core/lib/construct.ts:84:28)
at Function.synth (/Users/user/cdk/demo/node_modules/@aws-cdk/core/lib/construct.ts:41:10)
at App.synth (/Users/user/cdk/demo/node_modules/@aws-cdk/core/lib/app.ts:128:36)
at process.<anonymous> (/Users/user/cdk/demo/node_modules/@aws-cdk/core/lib/app.ts:111:45)
at Object.onceWrapper (events.js:284:20)
at process.emit (events.js:196:13)
at process.EventEmitter.emit (domain.js:471:20)
Issue Analytics
- State:
- Created 4 years ago
- Reactions:6
- Comments:30 (17 by maintainers)
Top GitHub Comments
@AreebSiddiqui there are a few ways you can break this dependency. The simplest might be to move the CodePipeline’s S3 Bucket to the same Stack as your CodeBuild Project:
@skinny85 This was a lifesaver, thank you so much. It’s because of people like you that the aws community is ever going, keep up the good work really appreciate it. Thanks again!