Skip to content

(route53): RecordSetName incorrectly assumes zone name doesn't end with period when hostedzone.zonename is token #20389

@peterwoodworth

Description

@peterwoodworth

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:

return `${providedName}${suffix}.`;

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/aws-route53Related to Amazon Route 53bugThis issue is a bug.effort/smallSmall work item – less than a day of effortp2

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions