forked from aws/aws-cdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(codepipeline-actions): cross stack reference causes stack cycle i…
…n sources that use CloudWatch Events (aws#20149) When using a newly-created, CDK-managed resource, such as an S3 Bucket or a CodeCommit Repository, as the source of a CodePipeline, when it's in a different Stack than the pipeline (but in the same environment as it), and we use CloudWatch Events to trigger the pipeline from the source, that would result in a cycle: 1. Because the Event Rule is created in the source Stack, that Stack needs the name of the pipeline to trigger from the Rule, and also the Role to use for the trigger, which is created in the target (in this case, the pipeline) Stack. So, the source Stack depends on the pipeline Stack. 2. The pipeline Stack needs the name of the source resource. So, the pipeline Stack depends on the source Stack. The only way to break this cycle is to move the Event Rule to the target Stack. This PR adds an API to the Events module to make it possible for event-creating constructs to make that choice, and uses that capability in the CodePipeline `CodeCommitSourceAction` and `S3SourceAction`. Fixes aws#3087 Fixes aws#8042 Fixes aws#10896 ---- ### All Submissions: * [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md) ### Adding new Unconventional Dependencies: * [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md/#adding-new-unconventional-dependencies) ### New Features * [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/master/INTEGRATION_TESTS.md)? * [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information
1 parent
33030e0
commit 253d32e
Showing
12 changed files
with
2,453 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...s-cdk/aws-codepipeline-actions/test/s3/integ.source-bucket-events-cross-stack-same-env.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/// !cdk-integ PipelineStack | ||
|
||
import * as codebuild from '@aws-cdk/aws-codebuild'; | ||
import * as codepipeline from '@aws-cdk/aws-codepipeline'; | ||
import * as s3 from '@aws-cdk/aws-s3'; | ||
import { App, RemovalPolicy, Stack } from '@aws-cdk/core'; | ||
import * as integ from '@aws-cdk/integ-tests'; | ||
import * as cpactions from '../../lib'; | ||
|
||
const app = new App(); | ||
const bucketStack = new Stack(app, 'BucketStack'); | ||
const bucket = new s3.Bucket(bucketStack, 'Bucket', { | ||
removalPolicy: RemovalPolicy.DESTROY, | ||
}); | ||
|
||
const pipelineStack = new Stack(app, 'PipelineStack'); | ||
const sourceOutput = new codepipeline.Artifact(); | ||
new codepipeline.Pipeline(pipelineStack, 'Pipeline', { | ||
stages: [ | ||
{ | ||
stageName: 'Source', | ||
actions: [ | ||
new cpactions.S3SourceAction({ | ||
actionName: 'Source', | ||
bucket, | ||
trigger: cpactions.S3Trigger.EVENTS, | ||
bucketKey: 'file.zip', | ||
output: sourceOutput, | ||
}), | ||
], | ||
}, | ||
{ | ||
stageName: 'Build', | ||
actions: [ | ||
new cpactions.CodeBuildAction({ | ||
actionName: 'Build', | ||
project: new codebuild.PipelineProject(pipelineStack, 'Project'), | ||
input: sourceOutput, | ||
}), | ||
], | ||
}, | ||
], | ||
}); | ||
|
||
new integ.IntegTest(app, 'CodePipelineS3SourceTest', { | ||
testCases: [pipelineStack], | ||
}); |
30 changes: 30 additions & 0 deletions
30
...est/s3/source-bucket-events-cross-stack-same-env.integ.snapshot/BucketStack.template.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"Resources": { | ||
"Bucket83908E77": { | ||
"Type": "AWS::S3::Bucket", | ||
"UpdateReplacePolicy": "Delete", | ||
"DeletionPolicy": "Delete" | ||
} | ||
}, | ||
"Outputs": { | ||
"ExportsOutputRefBucket83908E7781C90AC0": { | ||
"Value": { | ||
"Ref": "Bucket83908E77" | ||
}, | ||
"Export": { | ||
"Name": "BucketStack:ExportsOutputRefBucket83908E7781C90AC0" | ||
} | ||
}, | ||
"ExportsOutputFnGetAttBucket83908E77Arn063C8555": { | ||
"Value": { | ||
"Fn::GetAtt": [ | ||
"Bucket83908E77", | ||
"Arn" | ||
] | ||
}, | ||
"Export": { | ||
"Name": "BucketStack:ExportsOutputFnGetAttBucket83908E77Arn063C8555" | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.