1
1
import codepipeline = require( '@aws-cdk/aws-codepipeline-api' ) ;
2
2
import iam = require( '@aws-cdk/aws-iam' ) ;
3
3
import cdk = require( '@aws-cdk/cdk' ) ;
4
+ import { ServerDeploymentGroupRef } from './deployment-group' ;
4
5
5
6
/**
6
7
* Construction properties of the {@link PipelineDeployAction CodeDeploy deploy CodePipeline Action}.
7
8
*/
8
9
export interface PipelineDeployActionProps extends codepipeline . CommonActionProps ,
9
10
codepipeline . CommonActionConstructProps {
10
11
/**
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.
23
13
*/
24
- deploymentGroupName : string ;
14
+ deploymentGroup : ServerDeploymentGroupRef ;
25
15
26
16
/**
27
17
* The source to use as input for deployment.
@@ -40,50 +30,37 @@ export class PipelineDeployAction extends codepipeline.DeployAction {
40
30
provider : 'CodeDeploy' ,
41
31
inputArtifact : props . inputArtifact ,
42
32
configuration : {
43
- ApplicationName : props . applicationName ,
44
- DeploymentGroupName : props . deploymentGroupName ,
33
+ ApplicationName : props . deploymentGroup . application . applicationName ,
34
+ DeploymentGroupName : props . deploymentGroup . deploymentGroupName ,
45
35
} ,
46
36
} ) ;
47
37
48
38
// permissions, based on:
49
39
// https://docs.aws.amazon.com/codedeploy/latest/userguide/auth-and-access-control-permissions-reference.html
50
40
51
- const applicationArn = cdk . ArnUtils . fromComponents ( {
52
- service : 'codedeploy' ,
53
- resource : 'application' ,
54
- resourceName : props . applicationName ,
55
- sep : ':' ,
56
- } ) ;
57
41
props . stage . pipeline . role . addToPolicy ( new iam . PolicyStatement ( )
58
- . addResource ( applicationArn )
42
+ . addResource ( props . deploymentGroup . application . applicationArn )
59
43
. addActions (
60
44
'codedeploy:GetApplicationRevision' ,
61
45
'codedeploy:RegisterApplicationRevision' ,
62
46
) ) ;
63
47
64
- const deploymentGroupArn = cdk . ArnUtils . fromComponents ( {
65
- service : 'codedeploy' ,
66
- resource : 'deploymentgroup' ,
67
- resourceName : `${ props . applicationName } /${ props . deploymentGroupName } ` ,
68
- sep : ':' ,
69
- } ) ;
70
48
props . stage . pipeline . role . addToPolicy ( new iam . PolicyStatement ( )
71
- . addResource ( deploymentGroupArn )
49
+ . addResource ( props . deploymentGroup . deploymentGroupArn )
72
50
. addActions (
73
51
'codedeploy:CreateDeployment' ,
74
52
'codedeploy:GetDeployment' ,
75
53
) ) ;
76
54
77
- const deployConfigArn = cdk . ArnUtils . fromComponents ( {
78
- service : 'codedeploy' ,
79
- resource : 'deploymentconfig' ,
80
- resourceName : '*' ,
81
- sep : ':' ,
82
- } ) ;
83
55
props . stage . pipeline . role . addToPolicy ( new iam . PolicyStatement ( )
84
- . addResource ( deployConfigArn )
56
+ . addResource ( props . deploymentGroup . deploymentConfig . deploymentConfigArn )
85
57
. addActions (
86
58
'codedeploy:GetDeploymentConfig' ,
87
59
) ) ;
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
+ }
88
65
}
89
66
}
0 commit comments