@@ -135,6 +135,33 @@ export class InstanceTagSet {
135
135
}
136
136
}
137
137
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
+
138
165
/**
139
166
* Construction properties for {@link ServerDeploymentGroup}.
140
167
*/
@@ -224,6 +251,11 @@ export interface ServerDeploymentGroupProps {
224
251
* @default false
225
252
*/
226
253
ignorePollAlarmsFailure ?: boolean ;
254
+
255
+ /**
256
+ * The auto-rollback configuration for this Deployment Group.
257
+ */
258
+ autoRollback ?: AutoRollbackConfig ;
227
259
}
228
260
229
261
/**
@@ -281,6 +313,7 @@ export class ServerDeploymentGroup extends ServerDeploymentGroupRef {
281
313
ec2TagSet : this . ec2TagSet ( props . ec2InstanceTags ) ,
282
314
onPremisesTagSet : this . onPremiseTagSet ( props . onPremiseInstanceTags ) ,
283
315
alarmConfiguration : new cdk . Token ( ( ) => this . renderAlarmConfiguration ( props . ignorePollAlarmsFailure ) ) ,
316
+ autoRollbackConfiguration : new cdk . Token ( ( ) => this . renderAutoRollbackConfiguration ( props . autoRollback ) ) ,
284
317
} ) ;
285
318
286
319
this . deploymentGroupName = resource . deploymentGroupName ;
@@ -455,6 +488,40 @@ export class ServerDeploymentGroup extends ServerDeploymentGroupRef {
455
488
ignorePollAlarmFailure,
456
489
} ;
457
490
}
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
+ }
458
525
}
459
526
460
527
function deploymentGroupName2Arn ( applicationName : string , deploymentGroupName : string ) : string {
0 commit comments