Skip to content

Commit

Permalink
feat(Route53): add support for RemovalPolicy in CrossAccountZoneDeleg…
Browse files Browse the repository at this point in the history
…ationRecord (#15782)

add support for RemovalPolicy in CrossAccountZoneDelegationRecord

closes #15211

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
ayush987goyal authored Jul 30, 2021
1 parent 08ebbae commit 9eea4b8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
10 changes: 9 additions & 1 deletion packages/@aws-cdk/aws-route53/lib/record-set.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as path from 'path';
import * as iam from '@aws-cdk/aws-iam';
import { CustomResource, CustomResourceProvider, CustomResourceProviderRuntime, Duration, IResource, Resource, Token } from '@aws-cdk/core';
import { CustomResource, CustomResourceProvider, CustomResourceProviderRuntime, Duration, IResource, RemovalPolicy, Resource, Token } from '@aws-cdk/core';
import { Construct } from 'constructs';
import { IAliasRecordTarget } from './alias-record-target';
import { IHostedZone } from './hosted-zone-ref';
Expand Down Expand Up @@ -659,6 +659,13 @@ export interface CrossAccountZoneDelegationRecordProps {
* @default Duration.days(2)
*/
readonly ttl?: Duration;

/**
* The removal policy to apply to the record set.
*
* @default RemovalPolicy.DESTROY
*/
readonly removalPolicy?: RemovalPolicy;
}

/**
Expand All @@ -685,6 +692,7 @@ export class CrossAccountZoneDelegationRecord extends CoreConstruct {
new CustomResource(this, 'CrossAccountZoneDelegationCustomResource', {
resourceType: CROSS_ACCOUNT_ZONE_DELEGATION_RESOURCE_TYPE,
serviceToken,
removalPolicy: props.removalPolicy,
properties: {
AssumeRoleArn: props.delegationRole.roleArn,
ParentZoneName: props.parentHostedZoneName,
Expand Down
9 changes: 7 additions & 2 deletions packages/@aws-cdk/aws-route53/test/record-set.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect, haveResource } from '@aws-cdk/assert-internal';
import { expect, haveResource, ResourcePart } from '@aws-cdk/assert-internal';
import * as iam from '@aws-cdk/aws-iam';
import { Duration, Stack } from '@aws-cdk/core';
import { Duration, RemovalPolicy, Stack } from '@aws-cdk/core';
import { nodeunitShim, Test } from 'nodeunit-shim';
import * as route53 from '../lib';

Expand Down Expand Up @@ -617,6 +617,7 @@ nodeunitShim({
parentHostedZoneId: parentZone.hostedZoneId,
delegationRole: parentZone.crossAccountZoneDelegationRole!,
ttl: Duration.seconds(60),
removalPolicy: RemovalPolicy.RETAIN,
});

// THEN
Expand Down Expand Up @@ -645,6 +646,10 @@ nodeunitShim({
},
TTL: 60,
}));
expect(stack).to(haveResource('Custom::CrossAccountZoneDelegation', {
DeletionPolicy: 'Retain',
UpdateReplacePolicy: 'Retain',
}, ResourcePart.CompleteDefinition));
test.done();
},

Expand Down

0 comments on commit 9eea4b8

Please sign in to comment.