Skip to content

Commit c35091f

Browse files
skinny85mergify[bot]
authored andcommitted
feat(codepipeline): validate that source actions are in the same region as the pipeline (#4303)
This is something that the CodePipeline API enforces in the backend, so we should validate it before, at synthesis time.
1 parent 2f979b7 commit c35091f

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

packages/@aws-cdk/aws-codepipeline/lib/pipeline.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import iam = require('@aws-cdk/aws-iam');
33
import kms = require('@aws-cdk/aws-kms');
44
import s3 = require('@aws-cdk/aws-s3');
55
import { App, Construct, Lazy, PhysicalName, RemovalPolicy, Resource, Stack, Token } from '@aws-cdk/core';
6-
import { IAction, IPipeline, IStage } from "./action";
6+
import { ActionCategory, IAction, IPipeline, IStage } from "./action";
77
import { CfnPipeline } from './codepipeline.generated';
88
import { CrossRegionSupportConstruct, CrossRegionSupportStack } from './cross-region-support-stack';
99
import { FullActionDescriptor } from './full-action-descriptor';
@@ -402,6 +402,11 @@ export class Pipeline extends PipelineBase {
402402
};
403403
}
404404

405+
// source actions have to be in the same region as the pipeline
406+
if (action.actionProperties.category === ActionCategory.SOURCE) {
407+
throw new Error(`Source action '${action.actionProperties.actionName}' must be in the same region as the pipeline`);
408+
}
409+
405410
// check whether we already have a bucket in that region,
406411
// either passed from the outside or previously created
407412
let crossRegionSupport = this._crossRegionSupport[actionRegion];

packages/@aws-cdk/aws-codepipeline/test/fake-source-action.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ export interface FakeSourceActionProps extends codepipeline.CommonActionProps {
66
output: codepipeline.Artifact;
77

88
extraOutputs?: codepipeline.Artifact[];
9+
10+
region?: string;
911
}
1012

1113
export class FakeSourceAction implements codepipeline.IAction {

packages/@aws-cdk/aws-codepipeline/test/test.pipeline.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,26 @@ export = {
4646
},
4747

4848
'that is cross-region': {
49+
'validates that source actions are in the same account as the pipeline'(test: Test) {
50+
const app = new cdk.App();
51+
const stack = new cdk.Stack(app, 'PipelineStack', { env: { region: 'us-west-1', account: '123456789012' }});
52+
const pipeline = new codepipeline.Pipeline(stack, 'Pipeline');
53+
const sourceStage = pipeline.addStage({
54+
stageName: 'Source',
55+
});
56+
const sourceAction = new FakeSourceAction({
57+
actionName: 'FakeSource',
58+
output: new codepipeline.Artifact(),
59+
region: 'ap-southeast-1',
60+
});
61+
62+
test.throws(() => {
63+
sourceStage.addAction(sourceAction);
64+
}, /Source action 'FakeSource' must be in the same region as the pipeline/);
65+
66+
test.done();
67+
},
68+
4969
'allows passing an Alias in place of the KMS Key in the replication Bucket'(test: Test) {
5070
const app = new cdk.App();
5171

0 commit comments

Comments
 (0)