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(route-53): add ability to create NS Records #13895

Merged
merged 5 commits into from Apr 6, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions packages/@aws-cdk/aws-route53/README.md
Expand Up @@ -60,6 +60,22 @@ new route53.TxtRecord(this, 'TXTRecord', {
});
```

To add a NS record to your zone:

```ts
import * as route53 from '@aws-cdk/aws-route53';

new route53.NsRecord(this, 'NSRecord', {
zone: myZone,
recordName: 'foo',
values: [
'ns-1.awsdns.co.uk.',
'ns-2.awsdns.com.'
],
ttl: Duration.minutes(90), // Optional - default is 30 minutes
});
```

To add an A record to your zone:

```ts
Expand Down
25 changes: 25 additions & 0 deletions packages/@aws-cdk/aws-route53/lib/record-set.ts
Expand Up @@ -541,6 +541,31 @@ export class MxRecord extends RecordSet {
}
}

/**
* Construction properties for a NSRecord.
*/
export interface NsRecordProps extends RecordSetOptions {
/**
* The NS values.
*/
readonly values: string[];
}

/**
* A DNS NS record
*
* @resource AWS::Route53::RecordSet
*/
export class NsRecord extends RecordSet {
constructor(scope: Construct, id: string, props: NsRecordProps) {
super(scope, id, {
...props,
recordType: RecordType.NS,
target: RecordTarget.fromValues(...props.values),
});
}
}

/**
* Construction properties for a ZoneDelegationRecord
*/
Expand Down
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-route53/package.json
Expand Up @@ -112,6 +112,7 @@
"props-physical-name:@aws-cdk/aws-route53.CnameRecordProps",
"props-physical-name:@aws-cdk/aws-route53.HostedZoneProps",
"props-physical-name:@aws-cdk/aws-route53.MxRecordProps",
"props-physical-name:@aws-cdk/aws-route53.NsRecordProps",
"props-physical-name:@aws-cdk/aws-route53.PrivateHostedZoneProps",
"props-physical-name:@aws-cdk/aws-route53.PublicHostedZoneProps",
"props-physical-name:@aws-cdk/aws-route53.RecordSetProps",
Expand Down
31 changes: 31 additions & 0 deletions packages/@aws-cdk/aws-route53/test/record-set.test.ts
Expand Up @@ -485,6 +485,37 @@ nodeunitShim({
test.done();
},

'NS record'(test: Test) {
// GIVEN
const stack = new Stack();

const zone = new route53.HostedZone(stack, 'HostedZone', {
zoneName: 'myzone',
});

// WHEN
new route53.NsRecord(stack, 'NS', {
zone,
recordName: 'www',
values: ['ns-1.awsdns.co.uk.', 'ns-2.awsdns.com.'],
});

// THEN
expect(stack).to(haveResource('AWS::Route53::RecordSet', {
Name: 'www.myzone.',
Type: 'NS',
HostedZoneId: {
Ref: 'HostedZoneDB99F866',
},
ResourceRecords: [
'ns-1.awsdns.co.uk.',
'ns-2.awsdns.com.',
],
TTL: '1800',
}));
test.done();
},

'Zone delegation record'(test: Test) {
// GIVEN
const stack = new Stack();
Expand Down