aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.63k stars 3.91k forks source link

aws-route53: CrossAccountZoneDelegationRecord fails deployment when parentHostedZoneName contains a trailing dot #28623

Open ryderben opened 9 months ago

ryderben commented 9 months ago

Describe the bug

Currently deployments of stacks fail if they contain a CrossAccountZoneDelegationRecord where the parent hosted zone name has a trailing dot (supplied in construct property parentHostedZoneName).

Expected Behavior

Deployment is expected to work transparently, regardless of whether or not there is a trailing dot. This is expected since:

Current Behavior

CloudFormation deployment of the parent stack fails - in Events:

Status: CREATE_FAILED

Status reason: Received response status [FAILED] from custom resource. Message returned: Error: Expected one hosted zone to match the given name but found 0 at A (/var/task/index.js:1:1613) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async s (/var/task/index.js:1:1272) at async Runtime.handler (/var/task/__entrypoint__.js:1:932)

Reproduction Steps

  1. Follow instructions to create setup for Cross Account Zone Delegation - https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_route53-readme.html#cross-account-zone-delegation
  2. Modify parentHostedZoneName to contain a trailing dot.

Possible Solution

Change filter in custom resource handler to not append the trailing dot automatically: https://github.com/aws/aws-cdk/blob/3656a4c06539e68a2eda3d3b98f5d92e956dc37d/packages/%40aws-cdk/custom-resource-handlers/lib/aws-route53/cross-account-zone-delegation-handler/index.ts#L78-L83

The preceding ListHostedZonesByName call likely does not need to be changed (both formats should yield the same response), however this should be confirmed.

Additional Information/Context

No response

CDK CLI Version

2

Framework Version

No response

Node.js Version

18.18.2

OS

Amazon Linux 2

Language

TypeScript

Language Version

No response

Other information

No response

pahud commented 9 months ago

I am not sure if any breaking changes would incur but this sounds good to me. Any pull requests are welcome and appreciated.