From ce277899e9df2ae9d69e94bdaa931e130cd4c95a Mon Sep 17 00:00:00 2001 From: msysh Date: Sat, 17 Sep 2022 13:38:57 +0900 Subject: [PATCH] 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* --- packages/@aws-cdk/aws-codedeploy/lib/utils.ts | 8 ++++ .../aws-cdk-codedeploy-server-dg.assets.json | 6 +-- ...aws-cdk-codedeploy-server-dg.template.json | 3 ++ .../deployment-group.integ.snapshot/cdk.out | 2 +- .../integ.json | 2 +- .../manifest.json | 4 +- .../deployment-group.integ.snapshot/tree.json | 41 ++++++++++--------- .../test/server/deployment-group.test.ts | 36 ++++++++++++++++ 8 files changed, 76 insertions(+), 26 deletions(-) diff --git a/packages/@aws-cdk/aws-codedeploy/lib/utils.ts b/packages/@aws-cdk/aws-codedeploy/lib/utils.ts index 6c5381b0de96b..834e5afb506e9 100644 --- a/packages/@aws-cdk/aws-codedeploy/lib/utils.ts +++ b/packages/@aws-cdk/aws-codedeploy/lib/utils.ts @@ -58,6 +58,14 @@ CfnDeploymentGroup.AutoRollbackConfigurationProperty | undefined { } } + if (autoRollbackConfig.failedDeployment === false + && autoRollbackConfig.stoppedDeployment !== true + && autoRollbackConfig.deploymentInAlarm === false) { + return { + enabled: false, + }; + } + return events.length > 0 ? { enabled: true, diff --git a/packages/@aws-cdk/aws-codedeploy/test/server/deployment-group.integ.snapshot/aws-cdk-codedeploy-server-dg.assets.json b/packages/@aws-cdk/aws-codedeploy/test/server/deployment-group.integ.snapshot/aws-cdk-codedeploy-server-dg.assets.json index 2798a5e21b7ed..e8cf7cae4d1a1 100644 --- a/packages/@aws-cdk/aws-codedeploy/test/server/deployment-group.integ.snapshot/aws-cdk-codedeploy-server-dg.assets.json +++ b/packages/@aws-cdk/aws-codedeploy/test/server/deployment-group.integ.snapshot/aws-cdk-codedeploy-server-dg.assets.json @@ -1,7 +1,7 @@ { - "version": "20.0.0", + "version": "21.0.0", "files": { - "dae40555b89ef1d396d170d34f146291ebc161a078ebd48290cc01135f3291da": { + "5088f12eca5c246f5575ce7f87af7fe359933f451dfd57b1c97881139e63533b": { "source": { "path": "aws-cdk-codedeploy-server-dg.template.json", "packaging": "file" @@ -9,7 +9,7 @@ "destinations": { "current_account-current_region": { "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", - "objectKey": "dae40555b89ef1d396d170d34f146291ebc161a078ebd48290cc01135f3291da.json", + "objectKey": "5088f12eca5c246f5575ce7f87af7fe359933f451dfd57b1c97881139e63533b.json", "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" } } diff --git a/packages/@aws-cdk/aws-codedeploy/test/server/deployment-group.integ.snapshot/aws-cdk-codedeploy-server-dg.template.json b/packages/@aws-cdk/aws-codedeploy/test/server/deployment-group.integ.snapshot/aws-cdk-codedeploy-server-dg.template.json index c88eb3bf11754..7b5a855c7b85c 100644 --- a/packages/@aws-cdk/aws-codedeploy/test/server/deployment-group.integ.snapshot/aws-cdk-codedeploy-server-dg.template.json +++ b/packages/@aws-cdk/aws-codedeploy/test/server/deployment-group.integ.snapshot/aws-cdk-codedeploy-server-dg.template.json @@ -722,6 +722,9 @@ ], "Enabled": true }, + "AutoRollbackConfiguration": { + "Enabled": false + }, "AutoScalingGroups": [ { "Ref": "ASG46ED3070" diff --git a/packages/@aws-cdk/aws-codedeploy/test/server/deployment-group.integ.snapshot/cdk.out b/packages/@aws-cdk/aws-codedeploy/test/server/deployment-group.integ.snapshot/cdk.out index 588d7b269d34f..8ecc185e9dbee 100644 --- a/packages/@aws-cdk/aws-codedeploy/test/server/deployment-group.integ.snapshot/cdk.out +++ b/packages/@aws-cdk/aws-codedeploy/test/server/deployment-group.integ.snapshot/cdk.out @@ -1 +1 @@ -{"version":"20.0.0"} \ No newline at end of file +{"version":"21.0.0"} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-codedeploy/test/server/deployment-group.integ.snapshot/integ.json b/packages/@aws-cdk/aws-codedeploy/test/server/deployment-group.integ.snapshot/integ.json index 58f83ae205d9e..526dd5e6267fd 100644 --- a/packages/@aws-cdk/aws-codedeploy/test/server/deployment-group.integ.snapshot/integ.json +++ b/packages/@aws-cdk/aws-codedeploy/test/server/deployment-group.integ.snapshot/integ.json @@ -1,5 +1,5 @@ { - "version": "20.0.0", + "version": "21.0.0", "testCases": { "integ.deployment-group": { "stacks": [ diff --git a/packages/@aws-cdk/aws-codedeploy/test/server/deployment-group.integ.snapshot/manifest.json b/packages/@aws-cdk/aws-codedeploy/test/server/deployment-group.integ.snapshot/manifest.json index 76cea921604a5..13d311b7d7966 100644 --- a/packages/@aws-cdk/aws-codedeploy/test/server/deployment-group.integ.snapshot/manifest.json +++ b/packages/@aws-cdk/aws-codedeploy/test/server/deployment-group.integ.snapshot/manifest.json @@ -1,5 +1,5 @@ { - "version": "20.0.0", + "version": "21.0.0", "artifacts": { "Tree": { "type": "cdk:tree", @@ -23,7 +23,7 @@ "validateOnSynth": false, "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", - "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/dae40555b89ef1d396d170d34f146291ebc161a078ebd48290cc01135f3291da.json", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/5088f12eca5c246f5575ce7f87af7fe359933f451dfd57b1c97881139e63533b.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ diff --git a/packages/@aws-cdk/aws-codedeploy/test/server/deployment-group.integ.snapshot/tree.json b/packages/@aws-cdk/aws-codedeploy/test/server/deployment-group.integ.snapshot/tree.json index cf2da82803f45..ba0b61498e104 100644 --- a/packages/@aws-cdk/aws-codedeploy/test/server/deployment-group.integ.snapshot/tree.json +++ b/packages/@aws-cdk/aws-codedeploy/test/server/deployment-group.integ.snapshot/tree.json @@ -9,7 +9,7 @@ "path": "Tree", "constructInfo": { "fqn": "constructs.Construct", - "version": "10.1.85" + "version": "10.1.102" } }, "aws-cdk-codedeploy-server-dg": { @@ -91,8 +91,8 @@ "id": "Acl", "path": "aws-cdk-codedeploy-server-dg/VPC/PublicSubnet1/Acl", "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.1.85" + "fqn": "@aws-cdk/core.Resource", + "version": "0.0.0" } }, "RouteTable": { @@ -258,8 +258,8 @@ "id": "Acl", "path": "aws-cdk-codedeploy-server-dg/VPC/PublicSubnet2/Acl", "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.1.85" + "fqn": "@aws-cdk/core.Resource", + "version": "0.0.0" } }, "RouteTable": { @@ -425,8 +425,8 @@ "id": "Acl", "path": "aws-cdk-codedeploy-server-dg/VPC/PrivateSubnet1/Acl", "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.1.85" + "fqn": "@aws-cdk/core.Resource", + "version": "0.0.0" } }, "RouteTable": { @@ -544,8 +544,8 @@ "id": "Acl", "path": "aws-cdk-codedeploy-server-dg/VPC/PrivateSubnet2/Acl", "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.1.85" + "fqn": "@aws-cdk/core.Resource", + "version": "0.0.0" } }, "RouteTable": { @@ -936,16 +936,16 @@ "id": "SsmParameterValue:--aws--service--ami-amazon-linux-latest--amzn-ami-hvm-x86_64-gp2:C96584B6-F00A-464E-AD19-53AFF4B05118.Parameter", "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", "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.1.85" + "fqn": "@aws-cdk/core.CfnParameter", + "version": "0.0.0" } }, "SsmParameterValue:--aws--service--ami-amazon-linux-latest--amzn-ami-hvm-x86_64-gp2:C96584B6-F00A-464E-AD19-53AFF4B05118": { "id": "SsmParameterValue:--aws--service--ami-amazon-linux-latest--amzn-ami-hvm-x86_64-gp2:C96584B6-F00A-464E-AD19-53AFF4B05118", "path": "aws-cdk-codedeploy-server-dg/SsmParameterValue:--aws--service--ami-amazon-linux-latest--amzn-ami-hvm-x86_64-gp2:C96584B6-F00A-464E-AD19-53AFF4B05118", "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.1.85" + "fqn": "@aws-cdk/core.Resource", + "version": "0.0.0" } }, "ELB": { @@ -1190,6 +1190,9 @@ ], "enabled": true }, + "autoRollbackConfiguration": { + "enabled": false + }, "autoScalingGroups": [ { "Ref": "ASG46ED3070" @@ -1225,20 +1228,20 @@ "id": "Service-principalMap", "path": "aws-cdk-codedeploy-server-dg/Service-principalMap", "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.1.85" + "fqn": "@aws-cdk/core.CfnMapping", + "version": "0.0.0" } } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.1.85" + "fqn": "@aws-cdk/core.Stack", + "version": "0.0.0" } } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.1.85" + "fqn": "@aws-cdk/core.App", + "version": "0.0.0" } } } \ No newline at end of file diff --git a/packages/@aws-cdk/aws-codedeploy/test/server/deployment-group.test.ts b/packages/@aws-cdk/aws-codedeploy/test/server/deployment-group.test.ts index c01a8ae8ef34d..6b22a90cbeedb 100644 --- a/packages/@aws-cdk/aws-codedeploy/test/server/deployment-group.test.ts +++ b/packages/@aws-cdk/aws-codedeploy/test/server/deployment-group.test.ts @@ -412,6 +412,42 @@ describe('CodeDeploy Server Deployment Group', () => { expect(() => app.synth()).toThrow(/deploymentInAlarm/); }); + test('disable automatic rollback', () => { + const stack = new cdk.Stack(); + + new codedeploy.ServerDeploymentGroup(stack, 'DeploymentGroup', { + autoRollback: { + deploymentInAlarm: false, + failedDeployment: false, + }, + }); + + Template.fromStack(stack).hasResourceProperties('AWS::CodeDeploy::DeploymentGroup', { + 'AutoRollbackConfiguration': { + 'Enabled': false, + }, + }); + }); + + test('disable automatic rollback when all options are false', () => { + const stack = new cdk.Stack(); + + new codedeploy.ServerDeploymentGroup(stack, 'DeploymentGroup', { + autoRollback: { + deploymentInAlarm: false, + failedDeployment: false, + stoppedDeployment: false, + }, + }); + + Template.fromStack(stack).hasResourceProperties('AWS::CodeDeploy::DeploymentGroup', { + 'AutoRollbackConfiguration': { + 'Enabled': false, + }, + }); + }); + + test('can be used with an imported ALB Target Group as the load balancer', () => { const stack = new cdk.Stack();