@@ -135,6 +135,33 @@ export class InstanceTagSet {
135135 }
136136}
137137
138+ /**
139+ * The configuration for automatically rolling back deployments in a given Deployment Group.
140+ */
141+ export interface AutoRollbackConfig {
142+ /**
143+ * Whether to automatically roll back a deployment that fails.
144+ *
145+ * @default true
146+ */
147+ failedDeployment ?: boolean ;
148+
149+ /**
150+ * Whether to automatically roll back a deployment that was manually stopped.
151+ *
152+ * @default false
153+ */
154+ stoppedDeployment ?: boolean ;
155+
156+ /**
157+ * Whether to automatically roll back a deployment during which one of the configured
158+ * CloudWatch alarms for this Deployment Group went off.
159+ *
160+ * @default true if you've provided any Alarms with the `alarms` property, false otherwise
161+ */
162+ deploymentInAlarm ?: boolean ;
163+ }
164+
138165/**
139166 * Construction properties for {@link ServerDeploymentGroup}.
140167 */
@@ -224,6 +251,11 @@ export interface ServerDeploymentGroupProps {
224251 * @default false
225252 */
226253 ignorePollAlarmsFailure ?: boolean ;
254+
255+ /**
256+ * The auto-rollback configuration for this Deployment Group.
257+ */
258+ autoRollback ?: AutoRollbackConfig ;
227259}
228260
229261/**
@@ -281,6 +313,7 @@ export class ServerDeploymentGroup extends ServerDeploymentGroupRef {
281313 ec2TagSet : this . ec2TagSet ( props . ec2InstanceTags ) ,
282314 onPremisesTagSet : this . onPremiseTagSet ( props . onPremiseInstanceTags ) ,
283315 alarmConfiguration : new cdk . Token ( ( ) => this . renderAlarmConfiguration ( props . ignorePollAlarmsFailure ) ) ,
316+ autoRollbackConfiguration : new cdk . Token ( ( ) => this . renderAutoRollbackConfiguration ( props . autoRollback ) ) ,
284317 } ) ;
285318
286319 this . deploymentGroupName = resource . deploymentGroupName ;
@@ -455,6 +488,40 @@ export class ServerDeploymentGroup extends ServerDeploymentGroupRef {
455488 ignorePollAlarmFailure,
456489 } ;
457490 }
491+
492+ private renderAutoRollbackConfiguration ( autoRollbackConfig : AutoRollbackConfig = { } ) :
493+ cloudformation . DeploymentGroupResource . AutoRollbackConfigurationProperty | undefined {
494+ const events = new Array < string > ( ) ;
495+
496+ // we roll back failed deployments by default
497+ if ( autoRollbackConfig . failedDeployment !== false ) {
498+ events . push ( 'DEPLOYMENT_FAILURE' ) ;
499+ }
500+
501+ // we _do not_ roll back stopped deployments by default
502+ if ( autoRollbackConfig . stoppedDeployment === true ) {
503+ events . push ( 'DEPLOYMENT_STOP_ON_REQUEST' ) ;
504+ }
505+
506+ // we _do not_ roll back alarm-triggering deployments by default
507+ // unless the Deployment Group has at least one alarm
508+ if ( autoRollbackConfig . deploymentInAlarm !== false ) {
509+ if ( this . alarms . length > 0 ) {
510+ events . push ( 'DEPLOYMENT_STOP_ON_ALARM' ) ;
511+ } else if ( autoRollbackConfig . deploymentInAlarm === true ) {
512+ throw new Error (
513+ "The auto-rollback setting 'deploymentInAlarm' does not have any effect unless you associate " +
514+ "at least one CloudWatch alarm with the Deployment Group" ) ;
515+ }
516+ }
517+
518+ return events . length > 0
519+ ? {
520+ enabled : true ,
521+ events,
522+ }
523+ : undefined ;
524+ }
458525}
459526
460527function deploymentGroupName2Arn ( applicationName : string , deploymentGroupName : string ) : string {
0 commit comments