Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Route53): add support for RemovalPolicy in CrossAccountZoneDelegationRecord #15782

Merged
merged 2 commits into from
Jul 30, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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