Skip to content

Commit

Permalink
fix(core): UpdateReplacePolicy mirrors DeletionPolicy (#3217)
Browse files Browse the repository at this point in the history
When setting the DeletionPolicy, the UpdateReplacePolicy should also be
set. There's the same implication of data loss for one and the other.

Fixes #2901.
  • Loading branch information
rix0rrr authored Jul 8, 2019
1 parent 7d020f1 commit d61bd2c
Show file tree
Hide file tree
Showing 89 changed files with 388 additions and 165 deletions.
3 changes: 2 additions & 1 deletion packages/@aws-cdk/app-delivery/test/integ.cicd.expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"Resources": {
"ArtifactBucket7410C9EF": {
"Type": "AWS::S3::Bucket",
"DeletionPolicy": "Delete"
"DeletionPolicy": "Delete",
"UpdateReplacePolicy": "Delete"
},
"CodePipelineRoleB3A660B4": {
"Type": "AWS::IAM::Role",
Expand Down
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-apigateway/lib/deployment.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CfnDeletionPolicy, Construct, Lazy, Resource, Stack } from '@aws-cdk/core';
import { Construct, Lazy, RemovalPolicy, Resource, Stack } from '@aws-cdk/core';
import crypto = require('crypto');
import { CfnDeployment, CfnDeploymentProps } from './apigateway.generated';
import { IRestApi } from './restapi';
Expand Down Expand Up @@ -72,7 +72,7 @@ export class Deployment extends Resource {
});

if (props.retainDeployments) {
this.resource.cfnOptions.deletionPolicy = CfnDeletionPolicy.RETAIN;
this.resource.applyRemovalPolicy(RemovalPolicy.RETAIN);
}

this.api = props.api;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"myapiv1toysPUT59AFBBC2",
"myapiv1toysA55FCBC4"
],
"DeletionPolicy": "Retain"
"DeletionPolicy": "Retain",
"UpdateReplacePolicy": "Retain"
},
"myapiDeploymentStagebeta96434BEB": {
"Type": "AWS::ApiGateway::Stage",
Expand Down
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-apigateway/test/test.deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ export = {
Ref: "apiC8550315"
}
},
DeletionPolicy: "Retain"
DeletionPolicy: "Retain",
UpdateReplacePolicy: "Retain"
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
},
"Message": "CustomResource says hello"
},
"DeletionPolicy": "Delete"
"DeletionPolicy": "Delete",
"UpdateReplacePolicy": "Delete"
},
"SingletonLambdaf7d4f7304ee111e89c2dfa7ae01bbebcServiceRoleFE9ABB04": {
"Type": "AWS::IAM::Role",
Expand Down Expand Up @@ -86,4 +87,4 @@
}
}
}
}
}
3 changes: 3 additions & 0 deletions packages/@aws-cdk/aws-cloudformation/test/test.resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export = testCase({
// THEN
expect(stack).to(haveResource('AWS::CloudFormation::CustomResource', {
DeletionPolicy: 'Retain',
UpdateReplacePolicy: 'Retain',
}, ResourcePart.CompleteDefinition));

test.done();
Expand Down Expand Up @@ -112,6 +113,7 @@ export = testCase({
"Custom1D319B237": {
"Type": "AWS::CloudFormation::CustomResource",
"DeletionPolicy": "Delete",
"UpdateReplacePolicy": "Delete",
"Properties": {
"ServiceToken": {
"Fn::GetAtt": [
Expand All @@ -124,6 +126,7 @@ export = testCase({
"Custom2DD5FB44D": {
"Type": "AWS::CloudFormation::CustomResource",
"DeletionPolicy": "Delete",
"UpdateReplacePolicy": "Delete",
"Properties": {
"ServiceToken": {
"Fn::GetAtt": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"Resources": {
"Bucket83908E77": {
"DeletionPolicy": "Delete",
"UpdateReplacePolicy": "Delete",
"Type": "AWS::S3::Bucket"
},
"AnAmazingWebsiteProbablyCFDistribution47E3983B": {
Expand Down Expand Up @@ -72,7 +73,8 @@
},
"AnAmazingWebsiteProbably2LoggingBucket222F7CE9": {
"Type": "AWS::S3::Bucket",
"DeletionPolicy": "Retain"
"DeletionPolicy": "Retain",
"UpdateReplacePolicy": "Retain"
},
"AnAmazingWebsiteProbably2CFDistribution7C1CCD12": {
"Type": "AWS::CloudFront::Distribution",
Expand Down Expand Up @@ -140,4 +142,4 @@
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"Resources": {
"Bucket83908E77": {
"DeletionPolicy": "Delete",
"UpdateReplacePolicy": "Delete",
"Type": "AWS::S3::Bucket"
},
"MyDistributionCFDistributionDE147309": {
Expand Down Expand Up @@ -51,4 +52,4 @@
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"Resources": {
"Bucket83908E77": {
"DeletionPolicy": "Delete",
"UpdateReplacePolicy": "Delete",
"Type": "AWS::S3::Bucket"
},
"LambdaServiceRoleA8ED4D3B": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"Resources": {
"Bucket83908E77": {
"DeletionPolicy": "Delete",
"UpdateReplacePolicy": "Delete",
"Type": "AWS::S3::Bucket"
},
"BucketPolicyE9A3008A": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"Resources": {
"Bucket83908E77": {
"DeletionPolicy": "Delete",
"UpdateReplacePolicy": "Delete",
"Type": "AWS::S3::Bucket"
},
"MyDistributionCFDistributionDE147309": {
Expand Down
3 changes: 3 additions & 0 deletions packages/@aws-cdk/aws-cloudfront/test/test.basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export = {
"Bucket83908E77": {
"Type": "AWS::S3::Bucket",
"DeletionPolicy": "Retain",
"UpdateReplacePolicy": "Retain",
},
"AnAmazingWebsiteProbablyCFDistribution47E3983B": {
"Type": "AWS::CloudFront::Distribution",
Expand Down Expand Up @@ -194,6 +195,7 @@ export = {
"Bucket83908E77": {
"Type": "AWS::S3::Bucket",
"DeletionPolicy": "Retain",
"UpdateReplacePolicy": "Retain",
},
"AnAmazingWebsiteProbablyCFDistribution47E3983B": {
"Type": "AWS::CloudFront::Distribution",
Expand Down Expand Up @@ -272,6 +274,7 @@ export = {
"Bucket83908E77": {
"Type": "AWS::S3::Bucket",
"DeletionPolicy": "Retain",
"UpdateReplacePolicy": "Retain",
},
"AnAmazingWebsiteProbablyCFDistribution47E3983B": {
"Type": "AWS::CloudFront::Distribution",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
"Resources": {
"Bucket83908E77": {
"Type": "AWS::S3::Bucket",
"DeletionPolicy": "Delete"
"DeletionPolicy": "Delete",
"UpdateReplacePolicy": "Delete"
},
"TrailS30071F172": {
"Type": "AWS::S3::Bucket",
"DeletionPolicy": "Retain"
"DeletionPolicy": "Retain",
"UpdateReplacePolicy": "Retain"
},
"TrailS3PolicyE42170FE": {
"Type": "AWS::S3::BucketPolicy",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"Resources": {
"CacheBucket41D9D0B0": {
"DeletionPolicy": "Delete",
"UpdateReplacePolicy": "Delete",
"Type": "AWS::S3::Bucket"
},
"MyProjectRole9BBE5233": {
Expand Down Expand Up @@ -178,4 +179,4 @@
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
"AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cServiceRoleDefaultPolicy6BC8737C",
"AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cServiceRoleD788AA17"
],
"DeletionPolicy": "Delete"
"DeletionPolicy": "Delete",
"UpdateReplacePolicy": "Delete"
},
"AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cServiceRoleD788AA17": {
"Type": "AWS::IAM::Role",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"Resources": {
"MyRepoF4F48043": {
"DeletionPolicy": "Retain",
"UpdateReplacePolicy": "Retain",
"Type": "AWS::ECR::Repository",
"DeletionPolicy": "Retain"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"Resources": {
"MyBucketF68F3FF0": {
"DeletionPolicy": "Delete",
"UpdateReplacePolicy": "Delete",
"Type": "AWS::S3::Bucket"
},
"MyProjectRole9BBE5233": {
Expand Down Expand Up @@ -169,4 +170,4 @@
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"Resources": {
"MyBucketF68F3FF0": {
"DeletionPolicy": "Delete",
"UpdateReplacePolicy": "Delete",
"Type": "AWS::S3::Bucket"
},
"MyProjectRole9BBE5233": {
Expand Down Expand Up @@ -222,4 +223,4 @@
}
}
}
}
}
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-codebuild/test/test.codebuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,8 @@ export = {
"Resources": {
"MyBucketF68F3FF0": {
"Type": "AWS::S3::Bucket",
"DeletionPolicy": "Retain"
"DeletionPolicy": "Retain",
"UpdateReplacePolicy": "Retain"
},
"MyProjectRole9BBE5233": {
"Type": "AWS::IAM::Role",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@
"Version": "2012-10-17"
}
},
"DeletionPolicy": "Retain"
"DeletionPolicy": "Retain",
"UpdateReplacePolicy": "Retain"
},
"PipelineArtifactsBucket22248F97": {
"Type": "AWS::S3::Bucket",
Expand All @@ -127,7 +128,8 @@
]
}
},
"DeletionPolicy": "Retain"
"DeletionPolicy": "Retain",
"UpdateReplacePolicy": "Retain"
},
"PipelineRoleD68726F7": {
"Type": "AWS::IAM::Role",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@
"Version": "2012-10-17"
}
},
"DeletionPolicy": "Retain"
"DeletionPolicy": "Retain",
"UpdateReplacePolicy": "Retain"
},
"PipelineArtifactsBucket22248F97": {
"Type": "AWS::S3::Bucket",
Expand All @@ -177,7 +178,8 @@
]
}
},
"DeletionPolicy": "Retain"
"DeletionPolicy": "Retain",
"UpdateReplacePolicy": "Retain"
},
"PipelineRoleD68726F7": {
"Type": "AWS::IAM::Role",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@
"Version": "2012-10-17"
}
},
"DeletionPolicy": "Retain"
"DeletionPolicy": "Retain",
"UpdateReplacePolicy": "Retain"
},
"PipelineArtifactsBucket22248F97": {
"Type": "AWS::S3::Bucket",
Expand All @@ -102,7 +103,8 @@
]
}
},
"DeletionPolicy": "Retain"
"DeletionPolicy": "Retain",
"UpdateReplacePolicy": "Retain"
},
"PipelineRoleD68726F7": {
"Type": "AWS::IAM::Role",
Expand Down Expand Up @@ -573,7 +575,8 @@
"Status": "Enabled"
}
},
"DeletionPolicy": "Delete"
"DeletionPolicy": "Delete",
"UpdateReplacePolicy": "Delete"
},
"PipelineBucketawscdkcodepipelinelambdaPipeline87A4B3D3SourceEventRuleCE4D4505": {
"Type": "AWS::Events::Rule",
Expand Down Expand Up @@ -648,7 +651,8 @@
},
"CloudTrailS310CD22F2": {
"Type": "AWS::S3::Bucket",
"DeletionPolicy": "Retain"
"DeletionPolicy": "Retain",
"UpdateReplacePolicy": "Retain"
},
"CloudTrailS3PolicyEA49A03E": {
"Type": "AWS::S3::BucketPolicy",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"Status": "Enabled"
}
},
"DeletionPolicy": "Delete"
"DeletionPolicy": "Delete",
"UpdateReplacePolicy": "Delete"
},
"PipelineArtifactsBucketEncryptionKey01D58D69": {
"Type": "AWS::KMS::Key",
Expand Down Expand Up @@ -90,7 +91,8 @@
"Version": "2012-10-17"
}
},
"DeletionPolicy": "Retain"
"DeletionPolicy": "Retain",
"UpdateReplacePolicy": "Retain"
},
"PipelineArtifactsBucket22248F97": {
"Type": "AWS::S3::Bucket",
Expand All @@ -111,7 +113,8 @@
]
}
},
"DeletionPolicy": "Retain"
"DeletionPolicy": "Retain",
"UpdateReplacePolicy": "Retain"
},
"PipelineRoleD68726F7": {
"Type": "AWS::IAM::Role",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"Status": "Enabled"
}
},
"DeletionPolicy": "Delete"
"DeletionPolicy": "Delete",
"UpdateReplacePolicy": "Delete"
},
"MyPipelineRoleC0D47CA4": {
"Type": "AWS::IAM::Role",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"Status": "Enabled"
}
},
"DeletionPolicy": "Delete"
"DeletionPolicy": "Delete",
"UpdateReplacePolicy": "Delete"
},
"ActionRole60B0EDF7": {
"Type": "AWS::IAM::Role",
Expand Down
Loading

0 comments on commit d61bd2c

Please sign in to comment.