-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
First classes for the CodeDeploy L2 #641
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given the name of those - I would remove the
Server
part of the class names (ServerDeploymentGroup
,ServerApplication
).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't - we'll have
LambdaApplication
andLambdaDeploymentGroup
soon, and in the futureContainerApplication
andContainerDeploymentGroup
, and possibly others.