Skip to content

Commit

Permalink
feat(codepipeline): validate that source actions are in the same regi…
Browse files Browse the repository at this point in the history
…on as the pipeline (#4303)

This is something that the CodePipeline API enforces in the backend,
so we should validate it before, at synthesis time.
  • Loading branch information
skinny85 authored and mergify[bot] committed Oct 1, 2019
1 parent 2f979b7 commit c35091f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/@aws-cdk/aws-codepipeline/lib/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import iam = require('@aws-cdk/aws-iam');
import kms = require('@aws-cdk/aws-kms');
import s3 = require('@aws-cdk/aws-s3');
import { App, Construct, Lazy, PhysicalName, RemovalPolicy, Resource, Stack, Token } from '@aws-cdk/core';
import { IAction, IPipeline, IStage } from "./action";
import { ActionCategory, IAction, IPipeline, IStage } from "./action";
import { CfnPipeline } from './codepipeline.generated';
import { CrossRegionSupportConstruct, CrossRegionSupportStack } from './cross-region-support-stack';
import { FullActionDescriptor } from './full-action-descriptor';
Expand Down Expand Up @@ -402,6 +402,11 @@ export class Pipeline extends PipelineBase {
};
}

// source actions have to be in the same region as the pipeline
if (action.actionProperties.category === ActionCategory.SOURCE) {
throw new Error(`Source action '${action.actionProperties.actionName}' must be in the same region as the pipeline`);
}

// check whether we already have a bucket in that region,
// either passed from the outside or previously created
let crossRegionSupport = this._crossRegionSupport[actionRegion];
Expand Down
2 changes: 2 additions & 0 deletions packages/@aws-cdk/aws-codepipeline/test/fake-source-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ export interface FakeSourceActionProps extends codepipeline.CommonActionProps {
output: codepipeline.Artifact;

extraOutputs?: codepipeline.Artifact[];

region?: string;
}

export class FakeSourceAction implements codepipeline.IAction {
Expand Down
20 changes: 20 additions & 0 deletions packages/@aws-cdk/aws-codepipeline/test/test.pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,26 @@ export = {
},

'that is cross-region': {
'validates that source actions are in the same account as the pipeline'(test: Test) {
const app = new cdk.App();
const stack = new cdk.Stack(app, 'PipelineStack', { env: { region: 'us-west-1', account: '123456789012' }});
const pipeline = new codepipeline.Pipeline(stack, 'Pipeline');
const sourceStage = pipeline.addStage({
stageName: 'Source',
});
const sourceAction = new FakeSourceAction({
actionName: 'FakeSource',
output: new codepipeline.Artifact(),
region: 'ap-southeast-1',
});

test.throws(() => {
sourceStage.addAction(sourceAction);
}, /Source action 'FakeSource' must be in the same region as the pipeline/);

test.done();
},

'allows passing an Alias in place of the KMS Key in the replication Bucket'(test: Test) {
const app = new cdk.App();

Expand Down

0 comments on commit c35091f

Please sign in to comment.