-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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): first classes for the CodeDeploy Construct Libr…
…ary. Includes ServerApplication and ServerDeploymentGroup.
- Loading branch information
Showing
6 changed files
with
306 additions
and
18 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
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,106 @@ | ||
import cdk = require('@aws-cdk/cdk'); | ||
import { ApplicationName, cloudformation } from './codedeploy.generated'; | ||
|
||
export class ApplicationArn extends cdk.Arn {} | ||
|
||
/** | ||
* Properties of a reference to a CodeDeploy EC2/on-premise Application. | ||
* | ||
* @see ServerApplicationRef#import | ||
* @see ServerApplicationRef#export | ||
*/ | ||
export interface ServerApplicationRefProps { | ||
/** | ||
* The physical, human-readable name of the CodeDeploy EC2/on-premise Application we're referencing. | ||
* The Application must be in the same account and region as the root Stack. | ||
*/ | ||
applicationName: ApplicationName; | ||
} | ||
|
||
/** | ||
* Represents a reference to a CodeDeploy Application deploying to EC2/on-premise instances. | ||
* | ||
* If you're managing the Application alongside the rest of your CDK resources, | ||
* use the {@link ServerApplication} class. | ||
* | ||
* If you want to reference an already existing Application, | ||
* or one defined in a different CDK Stack, | ||
* use the {@link #import} method. | ||
*/ | ||
export abstract class ServerApplicationRef extends cdk.Construct { | ||
/** | ||
* Import an Application defined either outside the CDK, | ||
* or in a different CDK Stack and exported using the {@link #export} method. | ||
* | ||
* @param parent the parent Construct for this new Construct | ||
* @param id the logical ID of this new Construct | ||
* @param props the properties of the referenced Application | ||
* @returns a Construct representing a reference to an existing Application | ||
*/ | ||
public static import(parent: cdk.Construct, id: string, props: ServerApplicationRefProps): ServerApplicationRef { | ||
return new ImportedServerApplicationRef(parent, id, props); | ||
} | ||
|
||
public abstract readonly applicationArn: ApplicationArn; | ||
|
||
public abstract readonly applicationName: ApplicationName; | ||
|
||
public export(): ServerApplicationRefProps { | ||
return { | ||
applicationName: new cdk.Output(this, 'ApplicationName', { value: this.applicationName }).makeImportValue(), | ||
}; | ||
} | ||
} | ||
|
||
class ImportedServerApplicationRef extends ServerApplicationRef { | ||
public readonly applicationArn: ApplicationArn; | ||
public readonly applicationName: ApplicationName; | ||
|
||
constructor(parent: cdk.Construct, id: string, props: ServerApplicationRefProps) { | ||
super(parent, id); | ||
|
||
this.applicationName = props.applicationName; | ||
this.applicationArn = applicationName2Arn(this.applicationName); | ||
} | ||
} | ||
|
||
/** | ||
* Construction properties for {@link ServerApplication}. | ||
*/ | ||
export interface ServerApplicationProps { | ||
/** | ||
* The physical, human-readable name of the CodeDeploy Application. | ||
* | ||
* @default an auto-generated name will be used | ||
*/ | ||
applicationName?: string; | ||
} | ||
|
||
/** | ||
* A CodeDeploy Application that deploys to EC2/on-premise instances. | ||
*/ | ||
export class ServerApplication extends ServerApplicationRef { | ||
public readonly applicationArn: ApplicationArn; | ||
public readonly applicationName: ApplicationName; | ||
|
||
constructor(parent: cdk.Construct, id: string, props?: ServerApplicationProps) { | ||
super(parent, id); | ||
|
||
const resource = new cloudformation.ApplicationResource(this, 'Resource', { | ||
applicationName: props && props.applicationName, | ||
computePlatform: 'Server', | ||
}); | ||
|
||
this.applicationName = resource.ref; | ||
this.applicationArn = applicationName2Arn(this.applicationName); | ||
} | ||
} | ||
|
||
function applicationName2Arn(applicationName: ApplicationName): ApplicationArn { | ||
return cdk.Arn.fromComponents({ | ||
service: 'codedeploy', | ||
resource: 'application', | ||
resourceName: applicationName, | ||
sep: ':', | ||
}); | ||
} |
144 changes: 144 additions & 0 deletions
144
packages/@aws-cdk/aws-codedeploy/lib/deployment-group.ts
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,144 @@ | ||
import cdk = require("@aws-cdk/cdk"); | ||
import iam = require("../../aws-iam/lib/role"); | ||
import { ServerApplication, ServerApplicationRef } from "./application"; | ||
import { ApplicationName, cloudformation, DeploymentGroupName } from './codedeploy.generated'; | ||
|
||
export class DeploymentGroupArn extends cdk.Arn {} | ||
|
||
/** | ||
* Properties of a reference to a CodeDeploy EC2/on-premise Deployment Group. | ||
* | ||
* @see ServerDeploymentGroupRef#import | ||
* @see ServerDeploymentGroupRef#export | ||
*/ | ||
export interface ServerDeploymentGroupRefProps { | ||
/** | ||
* The reference to the CodeDeploy EC2/on-premise Application | ||
* that this Deployment Group belongs to. | ||
*/ | ||
application: ServerApplicationRef; | ||
|
||
/** | ||
* The physical, human-readable name of the CodeDeploy EC2/on-premise Deployment Group | ||
* that we are referencing. | ||
*/ | ||
deploymentGroupName: DeploymentGroupName; | ||
} | ||
|
||
/** | ||
* Represents a reference to a CodeDeploy EC2/on-premise Deployment Group. | ||
* | ||
* If you're managing the Deployment Group alongside the rest of your CDK resources, | ||
* use the {@link ServerDeploymentGroup} class. | ||
* | ||
* If you want to reference an already existing Deployment Group, | ||
* or one defined in a different CDK Stack, | ||
* use the {@link #import} method. | ||
*/ | ||
export abstract class ServerDeploymentGroupRef extends cdk.Construct { | ||
/** | ||
* Import an EC2/on-premise Deployment Group defined either outside the CDK, | ||
* or in a different CDK Stack and exported using the {@link #export} method. | ||
* | ||
* @param parent the parent Construct for this new Construct | ||
* @param id the logical ID of this new Construct | ||
* @param props the properties of the referenced Deployment Group | ||
* @returns a Construct representing a reference to an existing Deployment Group | ||
*/ | ||
public static import(parent: cdk.Construct, id: string, props: ServerDeploymentGroupRefProps): ServerDeploymentGroupRef { | ||
return new ImportedServerDeploymentGroupRef(parent, id, props); | ||
} | ||
|
||
public abstract readonly application: ServerApplicationRef; | ||
public abstract readonly deploymentGroupName: DeploymentGroupName; | ||
public abstract readonly deploymentGroupArn: DeploymentGroupArn; | ||
|
||
public export(): ServerDeploymentGroupRefProps { | ||
return { | ||
application: this.application, | ||
deploymentGroupName: new cdk.Output(this, 'DeploymentGroupName', { | ||
value: this.deploymentGroupName | ||
}).makeImportValue(), | ||
}; | ||
} | ||
} | ||
|
||
class ImportedServerDeploymentGroupRef extends ServerDeploymentGroupRef { | ||
public readonly application: ServerApplicationRef; | ||
public readonly deploymentGroupName: DeploymentGroupName; | ||
public readonly deploymentGroupArn: DeploymentGroupArn; | ||
|
||
constructor(parent: cdk.Construct, id: string, props: ServerDeploymentGroupRefProps) { | ||
super(parent, id); | ||
|
||
this.application = props.application; | ||
this.deploymentGroupName = props.deploymentGroupName; | ||
this.deploymentGroupArn = deploymentGroupName2Arn(props.application.applicationName, | ||
props.deploymentGroupName); | ||
} | ||
} | ||
|
||
/** | ||
* Construction properties for {@link ServerDeploymentGroup}. | ||
*/ | ||
export interface ServerDeploymentGroupProps { | ||
/** | ||
* The CodeDeploy EC2/on-premise Application this Deployment Group belongs to. | ||
* If you don't provide one, a new Application will be created. | ||
*/ | ||
application?: ServerApplicationRef; | ||
|
||
/** | ||
* The service Role of this Deployment Group. | ||
* If you don't provide one, a new Role will be created. | ||
*/ | ||
role?: iam.Role; | ||
|
||
/** | ||
* The physical, human-readable name of the CodeDeploy Deployment Group. | ||
* | ||
* @default an auto-generated name will be used | ||
*/ | ||
deploymentGroupName?: string; | ||
} | ||
|
||
/** | ||
* A CodeDeploy Deployment Group that deploys to EC2/on-premise instances. | ||
*/ | ||
export class ServerDeploymentGroup extends ServerDeploymentGroupRef { | ||
public readonly application: ServerApplicationRef; | ||
public readonly role: iam.Role; | ||
public readonly deploymentGroupArn: DeploymentGroupArn; | ||
public readonly deploymentGroupName: DeploymentGroupName; | ||
|
||
constructor(parent: cdk.Construct, id: string, props?: ServerDeploymentGroupProps) { | ||
super(parent, id); | ||
|
||
this.application = (props && props.application) || new ServerApplication(this, 'Application'); | ||
|
||
this.role = (props && props.role) || new iam.Role(this, 'Role', { | ||
assumedBy: new cdk.ServicePrincipal('codedeploy.amazonaws.com'), | ||
managedPolicyArns: ['arn:aws:iam::aws:policy/service-role/AWSCodeDeployRole'], | ||
}); | ||
|
||
const resource = new cloudformation.DeploymentGroupResource(this, 'Resource', { | ||
applicationName: this.application.applicationName, | ||
deploymentGroupName: props && props.deploymentGroupName, | ||
serviceRoleArn: this.role.roleArn, | ||
}); | ||
|
||
this.deploymentGroupName = resource.ref; | ||
this.deploymentGroupArn = deploymentGroupName2Arn(this.application.applicationName, | ||
this.deploymentGroupName); | ||
} | ||
} | ||
|
||
function deploymentGroupName2Arn(applicationName: ApplicationName, | ||
deploymentGroupName: DeploymentGroupName): DeploymentGroupArn { | ||
return cdk.Arn.fromComponents({ | ||
service: 'codedeploy', | ||
resource: 'deploymentgroup', | ||
resourceName: new cdk.FnJoin('/', [applicationName, deploymentGroupName]), | ||
sep: ':', | ||
}); | ||
} |
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