Skip to content

Commit ce27789

Browse files
authored
fix(codedeploy): unable to configure disable automatically rollback (#22083)
In creating a DeploymentGroup, auto rollback cannot be disabled because there is no way to set the enabled property of auto-rollback-configuration to false. Once automatically rollback is enabled, it cannot be disabled by deleting the `autoRollback` property or by setting both deploymentInAlarm and failedDeployment to false. The root cause of this bug is that if all autoRollback properties, `deploymentInAlarm`, `failedDeployment`, and `stoppedDeployment`, are false, `AutoRollbackConfig` is undefined and cannot be changed to disabled. To solve this bug, `autoRollback` is disabled (`{ enabled: false }`) if the properties of `autoRollback` are explicitly set to false. closes #21691 ---- ### All Submissions: * [ ] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) ### Adding new Unconventional Dependencies: * [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies) ### New Features * [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)? * [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent d0e0ab9 commit ce27789

File tree

8 files changed

+76
-26
lines changed

8 files changed

+76
-26
lines changed

packages/@aws-cdk/aws-codedeploy/lib/utils.ts

+8
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ CfnDeploymentGroup.AutoRollbackConfigurationProperty | undefined {
5858
}
5959
}
6060

61+
if (autoRollbackConfig.failedDeployment === false
62+
&& autoRollbackConfig.stoppedDeployment !== true
63+
&& autoRollbackConfig.deploymentInAlarm === false) {
64+
return {
65+
enabled: false,
66+
};
67+
}
68+
6169
return events.length > 0
6270
? {
6371
enabled: true,

packages/@aws-cdk/aws-codedeploy/test/server/deployment-group.integ.snapshot/aws-cdk-codedeploy-server-dg.assets.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
{
2-
"version": "20.0.0",
2+
"version": "21.0.0",
33
"files": {
4-
"dae40555b89ef1d396d170d34f146291ebc161a078ebd48290cc01135f3291da": {
4+
"5088f12eca5c246f5575ce7f87af7fe359933f451dfd57b1c97881139e63533b": {
55
"source": {
66
"path": "aws-cdk-codedeploy-server-dg.template.json",
77
"packaging": "file"
88
},
99
"destinations": {
1010
"current_account-current_region": {
1111
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
12-
"objectKey": "dae40555b89ef1d396d170d34f146291ebc161a078ebd48290cc01135f3291da.json",
12+
"objectKey": "5088f12eca5c246f5575ce7f87af7fe359933f451dfd57b1c97881139e63533b.json",
1313
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
1414
}
1515
}

packages/@aws-cdk/aws-codedeploy/test/server/deployment-group.integ.snapshot/aws-cdk-codedeploy-server-dg.template.json

+3
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,9 @@
722722
],
723723
"Enabled": true
724724
},
725+
"AutoRollbackConfiguration": {
726+
"Enabled": false
727+
},
725728
"AutoScalingGroups": [
726729
{
727730
"Ref": "ASG46ED3070"
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"version":"20.0.0"}
1+
{"version":"21.0.0"}

packages/@aws-cdk/aws-codedeploy/test/server/deployment-group.integ.snapshot/integ.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "20.0.0",
2+
"version": "21.0.0",
33
"testCases": {
44
"integ.deployment-group": {
55
"stacks": [

packages/@aws-cdk/aws-codedeploy/test/server/deployment-group.integ.snapshot/manifest.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "20.0.0",
2+
"version": "21.0.0",
33
"artifacts": {
44
"Tree": {
55
"type": "cdk:tree",
@@ -23,7 +23,7 @@
2323
"validateOnSynth": false,
2424
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}",
2525
"cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}",
26-
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/dae40555b89ef1d396d170d34f146291ebc161a078ebd48290cc01135f3291da.json",
26+
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/5088f12eca5c246f5575ce7f87af7fe359933f451dfd57b1c97881139e63533b.json",
2727
"requiresBootstrapStackVersion": 6,
2828
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
2929
"additionalDependencies": [

packages/@aws-cdk/aws-codedeploy/test/server/deployment-group.integ.snapshot/tree.json

+22-19
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"path": "Tree",
1010
"constructInfo": {
1111
"fqn": "constructs.Construct",
12-
"version": "10.1.85"
12+
"version": "10.1.102"
1313
}
1414
},
1515
"aws-cdk-codedeploy-server-dg": {
@@ -91,8 +91,8 @@
9191
"id": "Acl",
9292
"path": "aws-cdk-codedeploy-server-dg/VPC/PublicSubnet1/Acl",
9393
"constructInfo": {
94-
"fqn": "constructs.Construct",
95-
"version": "10.1.85"
94+
"fqn": "@aws-cdk/core.Resource",
95+
"version": "0.0.0"
9696
}
9797
},
9898
"RouteTable": {
@@ -258,8 +258,8 @@
258258
"id": "Acl",
259259
"path": "aws-cdk-codedeploy-server-dg/VPC/PublicSubnet2/Acl",
260260
"constructInfo": {
261-
"fqn": "constructs.Construct",
262-
"version": "10.1.85"
261+
"fqn": "@aws-cdk/core.Resource",
262+
"version": "0.0.0"
263263
}
264264
},
265265
"RouteTable": {
@@ -425,8 +425,8 @@
425425
"id": "Acl",
426426
"path": "aws-cdk-codedeploy-server-dg/VPC/PrivateSubnet1/Acl",
427427
"constructInfo": {
428-
"fqn": "constructs.Construct",
429-
"version": "10.1.85"
428+
"fqn": "@aws-cdk/core.Resource",
429+
"version": "0.0.0"
430430
}
431431
},
432432
"RouteTable": {
@@ -544,8 +544,8 @@
544544
"id": "Acl",
545545
"path": "aws-cdk-codedeploy-server-dg/VPC/PrivateSubnet2/Acl",
546546
"constructInfo": {
547-
"fqn": "constructs.Construct",
548-
"version": "10.1.85"
547+
"fqn": "@aws-cdk/core.Resource",
548+
"version": "0.0.0"
549549
}
550550
},
551551
"RouteTable": {
@@ -936,16 +936,16 @@
936936
"id": "SsmParameterValue:--aws--service--ami-amazon-linux-latest--amzn-ami-hvm-x86_64-gp2:C96584B6-F00A-464E-AD19-53AFF4B05118.Parameter",
937937
"path": "aws-cdk-codedeploy-server-dg/SsmParameterValue:--aws--service--ami-amazon-linux-latest--amzn-ami-hvm-x86_64-gp2:C96584B6-F00A-464E-AD19-53AFF4B05118.Parameter",
938938
"constructInfo": {
939-
"fqn": "constructs.Construct",
940-
"version": "10.1.85"
939+
"fqn": "@aws-cdk/core.CfnParameter",
940+
"version": "0.0.0"
941941
}
942942
},
943943
"SsmParameterValue:--aws--service--ami-amazon-linux-latest--amzn-ami-hvm-x86_64-gp2:C96584B6-F00A-464E-AD19-53AFF4B05118": {
944944
"id": "SsmParameterValue:--aws--service--ami-amazon-linux-latest--amzn-ami-hvm-x86_64-gp2:C96584B6-F00A-464E-AD19-53AFF4B05118",
945945
"path": "aws-cdk-codedeploy-server-dg/SsmParameterValue:--aws--service--ami-amazon-linux-latest--amzn-ami-hvm-x86_64-gp2:C96584B6-F00A-464E-AD19-53AFF4B05118",
946946
"constructInfo": {
947-
"fqn": "constructs.Construct",
948-
"version": "10.1.85"
947+
"fqn": "@aws-cdk/core.Resource",
948+
"version": "0.0.0"
949949
}
950950
},
951951
"ELB": {
@@ -1190,6 +1190,9 @@
11901190
],
11911191
"enabled": true
11921192
},
1193+
"autoRollbackConfiguration": {
1194+
"enabled": false
1195+
},
11931196
"autoScalingGroups": [
11941197
{
11951198
"Ref": "ASG46ED3070"
@@ -1225,20 +1228,20 @@
12251228
"id": "Service-principalMap",
12261229
"path": "aws-cdk-codedeploy-server-dg/Service-principalMap",
12271230
"constructInfo": {
1228-
"fqn": "constructs.Construct",
1229-
"version": "10.1.85"
1231+
"fqn": "@aws-cdk/core.CfnMapping",
1232+
"version": "0.0.0"
12301233
}
12311234
}
12321235
},
12331236
"constructInfo": {
1234-
"fqn": "constructs.Construct",
1235-
"version": "10.1.85"
1237+
"fqn": "@aws-cdk/core.Stack",
1238+
"version": "0.0.0"
12361239
}
12371240
}
12381241
},
12391242
"constructInfo": {
1240-
"fqn": "constructs.Construct",
1241-
"version": "10.1.85"
1243+
"fqn": "@aws-cdk/core.App",
1244+
"version": "0.0.0"
12421245
}
12431246
}
12441247
}

packages/@aws-cdk/aws-codedeploy/test/server/deployment-group.test.ts

+36
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,42 @@ describe('CodeDeploy Server Deployment Group', () => {
412412
expect(() => app.synth()).toThrow(/deploymentInAlarm/);
413413
});
414414

415+
test('disable automatic rollback', () => {
416+
const stack = new cdk.Stack();
417+
418+
new codedeploy.ServerDeploymentGroup(stack, 'DeploymentGroup', {
419+
autoRollback: {
420+
deploymentInAlarm: false,
421+
failedDeployment: false,
422+
},
423+
});
424+
425+
Template.fromStack(stack).hasResourceProperties('AWS::CodeDeploy::DeploymentGroup', {
426+
'AutoRollbackConfiguration': {
427+
'Enabled': false,
428+
},
429+
});
430+
});
431+
432+
test('disable automatic rollback when all options are false', () => {
433+
const stack = new cdk.Stack();
434+
435+
new codedeploy.ServerDeploymentGroup(stack, 'DeploymentGroup', {
436+
autoRollback: {
437+
deploymentInAlarm: false,
438+
failedDeployment: false,
439+
stoppedDeployment: false,
440+
},
441+
});
442+
443+
Template.fromStack(stack).hasResourceProperties('AWS::CodeDeploy::DeploymentGroup', {
444+
'AutoRollbackConfiguration': {
445+
'Enabled': false,
446+
},
447+
});
448+
});
449+
450+
415451
test('can be used with an imported ALB Target Group as the load balancer', () => {
416452
const stack = new cdk.Stack();
417453

0 commit comments

Comments
 (0)