Skip to content

Commit

Permalink
dns: display error if zone domain does not match custom domain
Browse files Browse the repository at this point in the history
  • Loading branch information
fwang committed Aug 24, 2024
1 parent 75495a0 commit 304a319
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion platform/src/components/aws/dns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { ComponentResourceOptions, output } from "@pulumi/pulumi";
import { Transform, transform } from "../component";
import { Input } from "../input";
import { route53 } from "@pulumi/aws";
import { VisibleError } from "../error";

export interface DnsArgs {
/**
Expand Down Expand Up @@ -164,7 +165,17 @@ export function dns(args: DnsArgs = {}) {
return dnsRecord;

function lookupZone() {
if (args.zone) return args.zone;
if (args.zone) {
return output(args.zone).apply(async (zoneId) => {
const zone = await route53.getZone({ zoneId });
if (!partial.name.replace(/\.$/, "").endsWith(zone.name)) {
throw new VisibleError(
`The DNS record "${partial.name}" cannot be created because the domain name does not match the hosted zone "${zone.name}" (${zoneId}).`,
);
}
return zoneId;
});
}

return new HostedZoneLookup(
`${namePrefix}${partial.type}ZoneLookup${nameSuffix}`,
Expand Down

2 comments on commit 304a319

@rbasto1
Copy link

@rbasto1 rbasto1 commented on 304a319 Sep 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @fwang, one of the aliases I have for my app is not in the hosted zone in my AWS account. CloudFront doesn't complain because the SSL certificate matches the name. And it used to work with sst even though it would create a couple of weird records in the hosted zone (which is what you are correctly preventing here), but at least the CloudFront distribution was always correct. With this change I can't deploy the app anymore. I'm thinking that instead of throwing, maybe sst should just show a message that it will not create a record on the zone for aliases X and Y because the name doesn't match the zone? I could open an issue asking for that, or I could try to contribute and implement it in a PR directly. Let me know your thoughts. Thanks.

@jayair
Copy link
Contributor

@jayair jayair commented on 304a319 Sep 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah can you open an issue and link to this?

Please sign in to comment.