Skip to content

Commit 2e797b5

Browse files
authored
Revert "fix(certificatemanager): unable to set removal policy on DnsValidatedCertificate (#22040)" (#22056)
This reverts commit b3c9464. ---- ### 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 b3c9464 commit 2e797b5

File tree

4 files changed

+2
-75
lines changed

4 files changed

+2
-75
lines changed

packages/@aws-cdk/aws-certificatemanager/lambda-packages/dns_validated_certificate_handler/lib/index.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,6 @@ exports.certificateRequestHandler = async function (event, context) {
300300
responseData.Arn = physicalResourceId = certificateArn;
301301
break;
302302
case 'Delete':
303-
if (event.ResourceProperties.RemovalPolicy === 'retain') {
304-
break;
305-
}
306303
physicalResourceId = event.PhysicalResourceId;
307304
// If the resource didn't create correctly, the physical resource ID won't be the
308305
// certificate ARN, so don't try to delete it in that case.

packages/@aws-cdk/aws-certificatemanager/lambda-packages/dns_validated_certificate_handler/test/handler.test.js

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -835,38 +835,6 @@ describe('DNS Validated Certificate Handler', () => {
835835
});
836836
});
837837

838-
test('Delete operation does not delete the certificate if RemovalPolicy===retain', () => {
839-
const describeCertificateFake = sinon.fake.resolves({
840-
Certificate: {
841-
CertificateArn: testCertificateArn,
842-
}
843-
});
844-
AWS.mock('ACM', 'describeCertificate', describeCertificateFake);
845-
846-
const deleteCertificateFake = sinon.fake.resolves({});
847-
AWS.mock('ACM', 'deleteCertificate', deleteCertificateFake);
848-
849-
const request = nock(ResponseURL).put('/', body => {
850-
return body.Status === 'SUCCESS';
851-
}).reply(200);
852-
853-
return LambdaTester(handler.certificateRequestHandler)
854-
.event({
855-
RequestType: 'Delete',
856-
RequestId: testRequestId,
857-
PhysicalResourceId: testCertificateArn,
858-
ResourceProperties: {
859-
Region: 'us-east-1',
860-
RemovalPolicy: 'retain',
861-
}
862-
})
863-
.expectResolve(() => {
864-
sinon.assert.notCalled(describeCertificateFake);
865-
sinon.assert.notCalled(deleteCertificateFake);
866-
expect(request.isDone()).toBe(true);
867-
});
868-
});
869-
870838
test('Delete operation is idempotent', () => {
871839
const error = new Error();
872840
error.name = 'ResourceNotFoundException';

packages/@aws-cdk/aws-certificatemanager/lib/dns-validated-certificate.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ export class DnsValidatedCertificate extends CertificateBase implements ICertifi
7979
private normalizedZoneName: string;
8080
private hostedZoneId: string;
8181
private domainName: string;
82-
private _removalPolicy?: cdk.RemovalPolicy;
8382

8483
constructor(scope: Construct, id: string, props: DnsValidatedCertificateProps) {
8584
super(scope, id);
@@ -133,7 +132,6 @@ export class DnsValidatedCertificate extends CertificateBase implements ICertifi
133132
HostedZoneId: this.hostedZoneId,
134133
Region: props.region,
135134
Route53Endpoint: props.route53Endpoint,
136-
RemovalPolicy: cdk.Lazy.any({ produce: () => this._removalPolicy }),
137135
// Custom resources properties are always converted to strings; might as well be explict here.
138136
CleanupRecords: props.cleanupRoute53Records ? 'true' : undefined,
139137
Tags: cdk.Lazy.list({ produce: () => this.tags.renderTags() }),
@@ -145,10 +143,6 @@ export class DnsValidatedCertificate extends CertificateBase implements ICertifi
145143
this.node.addValidation({ validate: () => this.validateDnsValidatedCertificate() });
146144
}
147145

148-
public applyRemovalPolicy(policy: cdk.RemovalPolicy): void {
149-
this._removalPolicy = policy;
150-
}
151-
152146
private validateDnsValidatedCertificate(): string[] {
153147
const errors: string[] = [];
154148
// Ensure the zone name is a parent zone of the certificate domain name

packages/@aws-cdk/aws-certificatemanager/test/dns-validated-certificate.test.ts

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Template } from '@aws-cdk/assertions';
22
import * as iam from '@aws-cdk/aws-iam';
33
import { HostedZone, PublicHostedZone } from '@aws-cdk/aws-route53';
4-
import { App, Stack, Token, Tags, RemovalPolicy } from '@aws-cdk/core';
4+
import { App, Stack, Token, Tags } from '@aws-cdk/core';
55
import { DnsValidatedCertificate } from '../lib/dns-validated-certificate';
66

77
test('creates CloudFormation Custom Resource', () => {
@@ -266,36 +266,4 @@ test('test transparency logging settings is passed to the custom resource', () =
266266
},
267267
CertificateTransparencyLoggingPreference: 'DISABLED',
268268
});
269-
});
270-
271-
test('can set removal policy', () => {
272-
const stack = new Stack();
273-
274-
const exampleDotComZone = new PublicHostedZone(stack, 'ExampleDotCom', {
275-
zoneName: 'example.com',
276-
});
277-
278-
const cert = new DnsValidatedCertificate(stack, 'Certificate', {
279-
domainName: 'test.example.com',
280-
hostedZone: exampleDotComZone,
281-
subjectAlternativeNames: ['test2.example.com'],
282-
cleanupRoute53Records: true,
283-
});
284-
cert.applyRemovalPolicy(RemovalPolicy.RETAIN);
285-
286-
Template.fromStack(stack).hasResourceProperties('AWS::CloudFormation::CustomResource', {
287-
DomainName: 'test.example.com',
288-
SubjectAlternativeNames: ['test2.example.com'],
289-
RemovalPolicy: 'retain',
290-
ServiceToken: {
291-
'Fn::GetAtt': [
292-
'CertificateCertificateRequestorFunction5E845413',
293-
'Arn',
294-
],
295-
},
296-
HostedZoneId: {
297-
Ref: 'ExampleDotCom4D1B83AA',
298-
},
299-
CleanupRecords: 'true',
300-
});
301-
});
269+
});

0 commit comments

Comments
 (0)