Skip to content

Commit e2768e8

Browse files
authoredJun 2, 2022
feat(pipelines): pass role to s3 source action (aws#20576)
Fixes aws#20556 Implements the role property for the `S3Source`, which is being passed down to the underlying `S3SourceAction`. ---- ### 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 * [x] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/master/INTEGRATION_TESTS.md)? * [x] 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*
1 parent 7f2fccc commit e2768e8

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed
 

‎packages/@aws-cdk/pipelines/lib/codepipeline/codepipeline-source.ts

+9
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,14 @@ export interface S3SourceOptions {
291291
* @default - The bucket name
292292
*/
293293
readonly actionName?: string;
294+
295+
/**
296+
* The role that will be assumed by the pipeline prior to executing
297+
* the `S3Source` action.
298+
*
299+
* @default - a new role will be generated
300+
*/
301+
readonly role?: iam.IRole;
294302
}
295303

296304
class S3Source extends CodePipelineSource {
@@ -309,6 +317,7 @@ class S3Source extends CodePipelineSource {
309317
bucketKey: this.objectKey,
310318
trigger: this.props.trigger,
311319
bucket: this.bucket,
320+
role: this.props.role,
312321
variablesNamespace,
313322
});
314323
}

‎packages/@aws-cdk/pipelines/test/codepipeline/codepipeline-sources.test.ts

+33
Original file line numberDiff line numberDiff line change
@@ -255,3 +255,36 @@ test('can use source attributes in pipeline', () => {
255255
],
256256
});
257257
});
258+
259+
test('pass role to s3 codepipeline source', () => {
260+
const bucket = new s3.Bucket(pipelineStack, 'Bucket');
261+
const role = new Role(pipelineStack, 'TestRole', {
262+
assumedBy: new AnyPrincipal(),
263+
});
264+
new ModernTestGitHubNpmPipeline(pipelineStack, 'Pipeline', {
265+
input: cdkp.CodePipelineSource.s3(bucket, 'thefile.zip', {
266+
role,
267+
}),
268+
});
269+
270+
Template.fromStack(pipelineStack).hasResourceProperties('AWS::CodePipeline::Pipeline', {
271+
Stages: Match.arrayWith([{
272+
Name: 'Source',
273+
Actions: [
274+
Match.objectLike({
275+
Configuration: Match.objectLike({
276+
S3Bucket: { Ref: Match.anyValue() },
277+
S3ObjectKey: 'thefile.zip',
278+
}),
279+
Name: { Ref: Match.anyValue() },
280+
RoleArn: {
281+
'Fn::GetAtt': [
282+
Match.stringLikeRegexp('TestRole.*'),
283+
'Arn',
284+
],
285+
},
286+
}),
287+
],
288+
}]),
289+
});
290+
});

0 commit comments

Comments
 (0)
Please sign in to comment.