Skip to content

Commit

Permalink
feat(route-53): add ability to create NS Records (#13895)
Browse files Browse the repository at this point in the history
Adds feature as requested in issue #13816
----
*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
stijnbrouwers committed Apr 6, 2021
1 parent 8e2325c commit 02c7c1d
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 0 deletions.
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

0 comments on commit 02c7c1d

Please sign in to comment.