aws-cdk
aws-cdk copied to clipboard
(route53): RecordSetName incorrectly assumes zone name doesn't end with period when hostedzone.zonename is token
Describe the bug
An extra, unnecessary period is added when the HostedZone.zoneName is a token. This can occur when you import a HostedZone and set the zoneName with Fn.import values. These imported values contain periods at the end of the name
Expected Behavior
RecordSet is created with correct name
Current Behavior
RecordSet is created with name that ends in two periods, resulting in deployment failure
Reproduction Steps
const dist = new Distribution(this, 'dist', {
defaultBehavior: {
origin: new S3Origin(new Bucket(this, 'bucket'))
}
})
const name = Fn.importValue('name');
const hzid = Fn.importValue('id');
const zone = HostedZone.fromHostedZoneAttributes(this, 'hz', {
hostedZoneId: hzid,
zoneName: name,
})
new RecordSet(this, 'Rs', {
recordType: RecordType.A,
target: RecordTarget.fromAlias(new CloudFrontTarget(dist)),
zone,
recordName: 'wafv2-staticwebsite.win-deploy.app.xc'
})
Possible Solution
Add a prop which can forcefully remove the period if desired by the user
Here: https://github.com/aws/aws-cdk/blob/2edcbba8e826a2a12c88d2943a0b19b67dec0e85/packages/%40aws-cdk/aws-route53/lib/util.ts#L66
if (hostedZoneName.isUnresolved() && forceRemovePeriodProp) {
return `${providedName}${suffix}`;
} else {
return `${providedName}${suffix}.`;
}
Not sure how else we'd be able to handle this since we can't know what the token's value will be at synth
Additional Information/Context
Originally reported internally P64092469
Can be worked around with escape hatches, but it would be nice if this could just work without that
CDK CLI Version
latest
Framework Version
No response
Node.js Version
16
OS
mac
Language
Typescript
Language Version
No response
Other information
No response