-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(aws-codedeploy): Add a CodeDeploy CodePipeline deployment Action.
- Loading branch information
Showing
7 changed files
with
465 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
export * from './pipeline-action'; | ||
|
||
// AWS::CodeDeploy CloudFormation Resources: | ||
export * from './codedeploy.generated'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import actions = require('@aws-cdk/aws-codepipeline-api'); | ||
import cdk = require('@aws-cdk/cdk'); | ||
|
||
/** | ||
* Construction properties of the {@link PipelineDeployAction CodeDeploy deploy CodePipeline Action}. | ||
*/ | ||
export interface PipelineDeployActionProps extends actions.CommonActionProps { | ||
/** | ||
* The name of the CodeDeploy application to deploy to. | ||
*/ | ||
application: string; | ||
|
||
/** | ||
* The name of the CodeDeploy deployment group to deploy to. | ||
*/ | ||
deploymentGroup: string; | ||
|
||
/** | ||
* The source to use as input for deployment. | ||
*/ | ||
inputArtifact: actions.Artifact; | ||
} | ||
|
||
export class PipelineDeployAction extends actions.DeployAction { | ||
constructor(parent: cdk.Construct, id: string, props: PipelineDeployActionProps) { | ||
super(parent, id, { | ||
stage: props.stage, | ||
artifactBounds: { minInputs: 1, maxInputs: 1, minOutputs: 0, maxOutputs: 0 }, | ||
provider: 'CodeDeploy', | ||
inputArtifact: props.inputArtifact, | ||
configuration: { | ||
ApplicationName: props.application, | ||
DeploymentGroupName: props.deploymentGroup, | ||
}, | ||
}); | ||
|
||
// permissions, based on: | ||
// https://docs.aws.amazon.com/codedeploy/latest/userguide/auth-and-access-control-permissions-reference.html | ||
|
||
const actionsOnApplicaiton = [ | ||
'codedeploy:GetApplicationRevision', | ||
'codedeploy:RegisterApplicationRevision', | ||
]; | ||
const applicationArn = cdk.Arn.fromComponents({ | ||
service: 'codedeploy', | ||
resource: 'application', | ||
resourceName: props.application, | ||
sep: ':', | ||
}); | ||
props.stage.pipelineRole.addToPolicy(new cdk.PolicyStatement() | ||
.addResource(applicationArn) | ||
.addActions(...actionsOnApplicaiton)); | ||
|
||
const actionsOnDeploymentGroup = [ | ||
'codedeploy:CreateDeployment', | ||
'codedeploy:GetDeployment', | ||
]; | ||
const deploymentGroupArn = cdk.Arn.fromComponents({ | ||
service: 'codedeploy', | ||
resource: 'deploymentgroup', | ||
resourceName: `${props.application}/${props.deploymentGroup}`, | ||
sep: ':', | ||
}); | ||
props.stage.pipelineRole.addToPolicy(new cdk.PolicyStatement() | ||
.addResource(deploymentGroupArn) | ||
.addActions(...actionsOnDeploymentGroup)); | ||
|
||
const actionsOnDeployConfig = [ | ||
'codedeploy:GetDeploymentConfig', | ||
]; | ||
const deployConfigArn = cdk.Arn.fromComponents({ | ||
service: 'codedeploy', | ||
resource: 'deploymentconfig', | ||
resourceName: '*', | ||
sep: ':', | ||
}); | ||
props.stage.pipelineRole.addToPolicy(new cdk.PolicyStatement() | ||
.addResource(deployConfigArn) | ||
.addActions(...actionsOnDeployConfig)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.