Skip to content

Commit ce999b6

Browse files
skinny85Rico Huijbers
authored and
Rico Huijbers
committedNov 8, 2018
feat(aws-codedeploy): CodeDeploy Pipeline Action using the L2 DeploymentGroup Construct. (#1085)
BREAKING CHANGE: this changes the API of the CodeDeploy Pipeline Action to take the DeploymentGroup AWS Construct as an argument instead of the names of the Application and Deployment Group.
1 parent 570bd9f commit ce999b6

File tree

3 files changed

+37
-44
lines changed

3 files changed

+37
-44
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,17 @@
11
import codepipeline = require('@aws-cdk/aws-codepipeline-api');
22
import iam = require('@aws-cdk/aws-iam');
33
import cdk = require('@aws-cdk/cdk');
4+
import { ServerDeploymentGroupRef } from './deployment-group';
45

56
/**
67
* Construction properties of the {@link PipelineDeployAction CodeDeploy deploy CodePipeline Action}.
78
*/
89
export interface PipelineDeployActionProps extends codepipeline.CommonActionProps,
910
codepipeline.CommonActionConstructProps {
1011
/**
11-
* The name of the CodeDeploy application to deploy to.
12-
*
13-
* @note this will most likely be changed to a proper CodeDeploy AWS Construct reference
14-
* once that functionality has been implemented for CodeDeploy
15-
*/
16-
applicationName: string;
17-
18-
/**
19-
* The name of the CodeDeploy deployment group to deploy to.
20-
*
21-
* @note this will most likely be changed to a proper CodeDeploy AWS Construct reference
22-
* once that functionality has been implemented for CodeDeploy
12+
* The CodeDeploy Deployment Group to deploy to.
2313
*/
24-
deploymentGroupName: string;
14+
deploymentGroup: ServerDeploymentGroupRef;
2515

2616
/**
2717
* The source to use as input for deployment.
@@ -40,50 +30,37 @@ export class PipelineDeployAction extends codepipeline.DeployAction {
4030
provider: 'CodeDeploy',
4131
inputArtifact: props.inputArtifact,
4232
configuration: {
43-
ApplicationName: props.applicationName,
44-
DeploymentGroupName: props.deploymentGroupName,
33+
ApplicationName: props.deploymentGroup.application.applicationName,
34+
DeploymentGroupName: props.deploymentGroup.deploymentGroupName,
4535
},
4636
});
4737

4838
// permissions, based on:
4939
// https://docs.aws.amazon.com/codedeploy/latest/userguide/auth-and-access-control-permissions-reference.html
5040

51-
const applicationArn = cdk.ArnUtils.fromComponents({
52-
service: 'codedeploy',
53-
resource: 'application',
54-
resourceName: props.applicationName,
55-
sep: ':',
56-
});
5741
props.stage.pipeline.role.addToPolicy(new iam.PolicyStatement()
58-
.addResource(applicationArn)
42+
.addResource(props.deploymentGroup.application.applicationArn)
5943
.addActions(
6044
'codedeploy:GetApplicationRevision',
6145
'codedeploy:RegisterApplicationRevision',
6246
));
6347

64-
const deploymentGroupArn = cdk.ArnUtils.fromComponents({
65-
service: 'codedeploy',
66-
resource: 'deploymentgroup',
67-
resourceName: `${props.applicationName}/${props.deploymentGroupName}`,
68-
sep: ':',
69-
});
7048
props.stage.pipeline.role.addToPolicy(new iam.PolicyStatement()
71-
.addResource(deploymentGroupArn)
49+
.addResource(props.deploymentGroup.deploymentGroupArn)
7250
.addActions(
7351
'codedeploy:CreateDeployment',
7452
'codedeploy:GetDeployment',
7553
));
7654

77-
const deployConfigArn = cdk.ArnUtils.fromComponents({
78-
service: 'codedeploy',
79-
resource: 'deploymentconfig',
80-
resourceName: '*',
81-
sep: ':',
82-
});
8355
props.stage.pipeline.role.addToPolicy(new iam.PolicyStatement()
84-
.addResource(deployConfigArn)
56+
.addResource(props.deploymentGroup.deploymentConfig.deploymentConfigArn)
8557
.addActions(
8658
'codedeploy:GetDeploymentConfig',
8759
));
60+
61+
// grant the ASG Role permissions to read from the Pipeline Bucket
62+
for (const asg of props.deploymentGroup.autoScalingGroups || []) {
63+
props.stage.pipeline.grantBucketRead(asg.role);
64+
}
8865
}
8966
}

‎packages/@aws-cdk/aws-codepipeline/test/integ.pipeline-code-deploy.expected.json

+22-5
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,10 @@
175175
{
176176
"Ref": "AWS::AccountId"
177177
},
178-
":application:IntegTestDeployApp"
178+
":application:",
179+
{
180+
"Ref": "CodeDeployApplicationE587C27C"
181+
}
179182
]
180183
]
181184
}
@@ -202,7 +205,14 @@
202205
{
203206
"Ref": "AWS::AccountId"
204207
},
205-
":deploymentgroup:IntegTestDeployApp/IntegTestDeploymentGroup"
208+
":deploymentgroup:",
209+
{
210+
"Ref": "CodeDeployApplicationE587C27C"
211+
},
212+
"/",
213+
{
214+
"Ref": "CodeDeployGroup58220FC8"
215+
}
206216
]
207217
]
208218
}
@@ -226,7 +236,10 @@
226236
{
227237
"Ref": "AWS::AccountId"
228238
},
229-
":deploymentconfig:*"
239+
":deploymentconfig:",
240+
{
241+
"Ref": "CustomDeployConfig52EEBC13"
242+
}
230243
]
231244
]
232245
}
@@ -296,8 +309,12 @@
296309
"Version": "1"
297310
},
298311
"Configuration": {
299-
"ApplicationName": "IntegTestDeployApp",
300-
"DeploymentGroupName": "IntegTestDeploymentGroup"
312+
"ApplicationName": {
313+
"Ref": "CodeDeployApplicationE587C27C"
314+
},
315+
"DeploymentGroupName": {
316+
"Ref": "CodeDeployGroup58220FC8"
317+
}
301318
},
302319
"InputArtifacts": [
303320
{

‎packages/@aws-cdk/aws-codepipeline/test/integ.pipeline-code-deploy.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const deploymentConfig = new codedeploy.ServerDeploymentConfig(stack, 'CustomDep
1515
minHealthyHostCount: 0,
1616
});
1717

18-
new codedeploy.ServerDeploymentGroup(stack, 'CodeDeployGroup', {
18+
const deploymentGroup = new codedeploy.ServerDeploymentGroup(stack, 'CodeDeployGroup', {
1919
application,
2020
deploymentGroupName: 'IntegTestDeploymentGroup',
2121
deploymentConfig,
@@ -38,8 +38,7 @@ bucket.addToPipeline(sourceStage, 'S3Source', {
3838
const deployStage = new codepipeline.Stage(stack, 'Deploy', { pipeline });
3939
new codedeploy.PipelineDeployAction(stack, 'CodeDeploy', {
4040
stage: deployStage,
41-
applicationName: 'IntegTestDeployApp',
42-
deploymentGroupName: 'IntegTestDeploymentGroup',
41+
deploymentGroup,
4342
});
4443

4544
app.run();

0 commit comments

Comments
 (0)