-
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): Deployment Configuration Construct.
Part of the work on a AWS Construct Library for CodeDeploy.
- Loading branch information
Showing
6 changed files
with
233 additions
and
2 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
155 changes: 155 additions & 0 deletions
155
packages/@aws-cdk/aws-codedeploy/lib/deployment-configuration.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,155 @@ | ||
import cdk = require('@aws-cdk/cdk'); | ||
import { cloudformation } from './codedeploy.generated'; | ||
|
||
export class DeploymentConfigurationName extends cdk.CloudFormationToken {} | ||
|
||
export class DeploymentConfigurationArn extends cdk.Arn {} | ||
|
||
/** | ||
* Represents a Deployment Configuration for an EC2/on-premise Deployment Group. | ||
*/ | ||
export interface ServerDeploymentConfiguration { | ||
readonly deploymentConfigurationName: DeploymentConfigurationName; | ||
readonly deploymentConfigurationArn: DeploymentConfigurationArn; | ||
} | ||
|
||
/** | ||
* Pre-defined Deployment Configurations for an EC2/on-premise Deployment Group. | ||
* | ||
* @see https://docs.aws.amazon.com/codedeploy/latest/userguide/deployment-configurations.html#deployment-configuration-server | ||
* @see #OneAtATime | ||
* @see #HalfAtATime | ||
* @see #AllAtOnce | ||
*/ | ||
export class PredefinedServerDeploymentConfiguration implements ServerDeploymentConfiguration { | ||
public static readonly OneAtATime = new PredefinedServerDeploymentConfiguration('CodeDeployDefault.OneAtATime'); | ||
public static readonly HalfAtATime = new PredefinedServerDeploymentConfiguration('CodeDeployDefault.HalfAtATime'); | ||
public static readonly AllAtOnce = new PredefinedServerDeploymentConfiguration('CodeDeployDefault.AllAtOnce'); | ||
|
||
public readonly deploymentConfigurationName: DeploymentConfigurationName; | ||
public readonly deploymentConfigurationArn: DeploymentConfigurationArn; | ||
|
||
private constructor(deploymentConfigurationName: string) { | ||
this.deploymentConfigurationName = new DeploymentConfigurationName(deploymentConfigurationName); | ||
this.deploymentConfigurationArn = deploymentConfigurationName2Arn(this.deploymentConfigurationName); | ||
} | ||
} | ||
|
||
export interface CustomServerDeploymentConfigurationRefProps { | ||
/** | ||
* The physical, human-readable name of the custom CodeDeploy EC2/on-premise Deployment Configuration | ||
* that we are referencing. | ||
*/ | ||
readonly deploymentConfigurationName: DeploymentConfigurationName; | ||
} | ||
|
||
/** | ||
* Reference to a custom Deployment Configuration for an EC2/on-premise Deployment Group. | ||
*/ | ||
export abstract class CustomServerDeploymentConfigurationRef extends cdk.Construct | ||
implements ServerDeploymentConfiguration { | ||
/** | ||
* Import a custom Deployment Configuration for 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 custom Deployment Configuration | ||
* @returns a Construct representing a reference to an existing custom Deployment Configuration | ||
*/ | ||
public static import(parent: cdk.Construct, id: string, props: CustomServerDeploymentConfigurationRefProps): | ||
CustomServerDeploymentConfigurationRef { | ||
return new ImportedCustomServerDeploymentConfigurationRef(parent, id, props); | ||
} | ||
|
||
public abstract readonly deploymentConfigurationName: DeploymentConfigurationName; | ||
public abstract readonly deploymentConfigurationArn: DeploymentConfigurationArn; | ||
|
||
public export(): CustomServerDeploymentConfigurationRefProps { | ||
return { | ||
deploymentConfigurationName: new cdk.Output(this, 'DeploymentConfigurationName', { | ||
value: this.deploymentConfigurationName, | ||
}).makeImportValue(), | ||
}; | ||
} | ||
} | ||
|
||
class ImportedCustomServerDeploymentConfigurationRef extends CustomServerDeploymentConfigurationRef { | ||
public readonly deploymentConfigurationName: DeploymentConfigurationName; | ||
public readonly deploymentConfigurationArn: DeploymentConfigurationArn; | ||
|
||
constructor(parent: cdk.Construct, id: string, props: CustomServerDeploymentConfigurationRefProps) { | ||
super(parent, id); | ||
|
||
this.deploymentConfigurationName = props.deploymentConfigurationName; | ||
this.deploymentConfigurationArn = deploymentConfigurationName2Arn(this.deploymentConfigurationName); | ||
} | ||
} | ||
|
||
/** | ||
* The possible representations of a healthy-host value - | ||
* either percent-based, or an absolute number. | ||
*/ | ||
export enum HostsRepresentation { | ||
NUMBER = 'HOST_COUNT', | ||
PERCENTAGE = 'FLEET_PERCENT' | ||
} | ||
|
||
export interface MinimumHealthyHosts { | ||
readonly representation: HostsRepresentation; | ||
|
||
readonly value: number; | ||
} | ||
|
||
/** | ||
* Construction properties of {@link CustomServerDeploymentConfiguration}. | ||
*/ | ||
export interface CustomServerDeploymentConfigurationProps { | ||
/** | ||
* The physical, human-readable name of the Deployment Configuration. | ||
* | ||
* @default a name will be auto-generated | ||
*/ | ||
deploymentConfigurationName?: string; | ||
|
||
/** | ||
* The minimum healhty hosts setting for this EC2/on-premise Deployment Configuration. | ||
*/ | ||
minimumHealthyHosts: MinimumHealthyHosts; | ||
} | ||
|
||
/** | ||
* A custom Deployment Configuration for an EC2/on-premise Deployment Group. | ||
*/ | ||
export class CustomServerDeploymentConfiguration extends CustomServerDeploymentConfigurationRef { | ||
public readonly deploymentConfigurationName: DeploymentConfigurationName; | ||
public readonly deploymentConfigurationArn: DeploymentConfigurationArn; | ||
public readonly minimumHealthyHosts: MinimumHealthyHosts; | ||
|
||
constructor(parent: cdk.Construct, id: string, props: CustomServerDeploymentConfigurationProps) { | ||
super(parent, id); | ||
|
||
this.minimumHealthyHosts = props.minimumHealthyHosts; | ||
|
||
const resource = new cloudformation.DeploymentConfigResource(this, 'Resource', { | ||
deploymentConfigName: props.deploymentConfigurationName, | ||
minimumHealthyHosts: { | ||
type: this.minimumHealthyHosts.representation.toString(), | ||
value: this.minimumHealthyHosts.value, | ||
}, | ||
}); | ||
|
||
this.deploymentConfigurationName = resource.ref; | ||
this.deploymentConfigurationArn = deploymentConfigurationName2Arn(this.deploymentConfigurationName); | ||
} | ||
} | ||
|
||
function deploymentConfigurationName2Arn(deploymentConfigurationName: DeploymentConfigurationName): | ||
DeploymentConfigurationArn { | ||
return cdk.Arn.fromComponents({ | ||
service: 'codedeploy', | ||
resource: 'deploymentconfig', | ||
resourceName: deploymentConfigurationName, | ||
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
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