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

fix: route53 CrossAccountZoneDelegationRecord fails at deployment time with imported delegatedZone #30440

Merged
merged 6 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/aws-cdk-lib/aws-route53/lib/record-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,10 @@ export class CrossAccountZoneDelegationRecord extends Construct {
throw Error('Only one of parentHostedZoneName and parentHostedZoneId is supported');
}

if (!props.delegatedZone.hostedZoneNameServers) {
aaythapa marked this conversation as resolved.
Show resolved Hide resolved
throw Error(`Not able to retrieve Name Servers for ${props.delegatedZone.zoneName} due to it being imported.`);
aaythapa marked this conversation as resolved.
Show resolved Hide resolved
}

const provider = CrossAccountZoneDelegationProvider.getOrCreateProvider(this, CROSS_ACCOUNT_ZONE_DELEGATION_RESOURCE_TYPE);

const role = iam.Role.fromRoleArn(this, 'cross-account-zone-delegation-handler-role', provider.roleArn);
Expand Down
21 changes: 21 additions & 0 deletions packages/aws-cdk-lib/aws-route53/test/record-set.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,27 @@ describe('record set', () => {
});
});

test('CrossAccountZoneDelegationRecord should throw if delegatedZone is imported', () => {
// GIVEN
const stack = new Stack();
const parentZone = new route53.PublicHostedZone(stack, 'ParentHostedZone', {
zoneName: 'myzone.com'
});

// WHEN
const childZone = route53.PublicHostedZone.fromPublicHostedZoneAttributes(stack, 'ChildHostedZone', {
hostedZoneId: 'fake-id',
zoneName: 'fake-name',
});

//THEN
expect(() => new route53.CrossAccountZoneDelegationRecord(stack, 'Delegation', {
delegatedZone: childZone,
parentHostedZoneId: parentZone.hostedZoneId,
delegationRole: parentZone.crossAccountZoneDelegationRole!,
})).toThrow(/Not able to retrieve Name Servers for fake-name due to it being imported./);
});

testDeprecated('Cross account zone delegation record with parentHostedZoneName', () => {
// GIVEN
const stack = new Stack();
Expand Down
Loading