Okay please.
I had a different stack which was already provisioning a hosted zone on the dev account.
So what I did was to create a StackReference to the nameserver file then return the
domainName and
nameServers.
const environment = pulumi.getStack();
const commonStack = new pulumi.StackReference(`example/${environment}`);
const subDNS = commonStack.getOutput("dns").apply((t) => {
return {
domainName: t.domainName as string,
nameServers: t.nameServers as string[]
};
});
After that, I set the credentials for the production account and exported it (for local testing).
I then retrieved the hosted zone from the production account.
const parentHostedZone = aws.route53.getZone({ name: exampleDomainName, privateZone: false });
After that, I created a Route53 record and passed the domainName and nameServers I had referenced from the other stack, and the zoneId of the production hosted zone
export const subdomainRecord = new aws.route53.Record(`${environment}-subdomain-record`, {
allowOverwrite: true,
name: subDNS.domainName,
type: "NS",
ttl: 300,
records: subDNS.nameServers,
zoneId: parentHostedZone.then(zr => zr.zoneId)
}, { protect: false });