in src/constructs/dns/dns-records.ts [25:69]
constructor(scope: GuStack, id: string, props: GuDnsRecordSetProps) {
const { name, recordType, resourceRecords, ttl } = props;
const { stage } = scope;
/*
Nodes in the CDK tree must have a unique ID. This class adds two nodes to the tree, so we have two IDs.
`id`, by definition, must be unique. `name` represents a fully qualified domain name, which must also be unique.
`id` being given to the level 1 construct means it also becomes the logicalId in the template.
*/
const level2ConstructId = `${name}-DnsRecordSet`;
const level1ConstructId = id;
super(scope, level2ConstructId);
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- more `RecordType`s will be added soon!
if (recordType === RecordType.CNAME) {
/*
If you try to create a CNAME with multiple records within NS1, you are greeted with:
According to RFC, a CNAME record should not return multiple answers.
Doing so may cause problems during resolution.
If you want to use multiple answers, you should ensure you have the correct filters in place (such as SELECT_FIRST_N 1) to limit them to a single answer at resolution time.
`Guardian::DNS::RecordSet` does not implement "correct filters", so fail fast by throwing.
*/
if (resourceRecords.length !== 1) {
throw new Error(
"According to RFC, a CNAME record should not return multiple answers. Doing so may cause problems during resolution.",
);
}
}
// The spec for this private resource type can be found here:
// https://github.com/guardian/cfn-private-resource-types/tree/main/dns/guardian-dns-record-set-type/docs#syntax
new CfnResource(scope, level1ConstructId, {
type: "Guardian::DNS::RecordSet",
properties: {
Name: name,
ResourceRecords: resourceRecords,
RecordType: recordType,
TTL: ttl.toSeconds(),
Stage: stage,
},
});
}