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

route53: Imported public hosted zone cannot be used to create VpcEndpointServiceDomainName #21004

Closed
aamielsan opened this issue Jul 5, 2022 · 3 comments · Fixed by #21007
Closed
Assignees
Labels
@aws-cdk/aws-route53 Related to Amazon Route 53 bug This issue is a bug. effort/small Small work item – less than a day of effort in-progress This issue is being actively worked on. p1

Comments

@aamielsan
Copy link

aamielsan commented Jul 5, 2022

Describe the bug

We're trying to enable private DNS for our VPC endpoint service using an imported public hosted zone.

Using PublicHostedZone.fromPublicHostedZoneId() to import the public hosted zone and passing it as a parameter for VpcEndpointServiceDomainName fails with the error:

Cannot reference `zoneName` when using `PublicHostedZone.fromPublicHostedZoneId()`.
A construct consuming this hosted zone may be trying to reference its `zoneName`.
If this is the case, use `fromPublicHostedZoneAttributes()` instead

But PublicHostedZone.fromPublicHostedZoneAttributes() returns IHostedZone, and using the imported public hosted zone as a parameter for VpcEndpointServiceDomainName results in a compilation error in Kotlin/Java:

Type mismatch.
Required: IPublicHostedZone
Found: IHostedZone

Expected Behavior

Expected PublicHostedZone.fromPublicHostedZoneAttributes() to return IPublicHostedZone.

This should also enable VpcEndpointServiceDomainName to be created with an imported public hosted zone.

Current Behavior

Using an imported public hosted zone from PublicHostedZone.fromPublicHostedZoneAttributes() to create a VpcEndpointServiceDomainName construct results to a compilation error in Kotlin/Java:

Type mismatch.
Required: IPublicHostedZone
Found: IHostedZone

Reproduction Steps

This test code fails to compile in Kotlin:

@Test
fun `imported hosted zone should enable private dns`() {
    val stack = Stack.Builder.create().build()
    val nlb = IVpcEndpointServiceLoadBalancer {
        "arn:aws:elasticloadbalancing:us-east-1:123456789012:loadbalancer/net/Test/9bn6qkf4e9jrw77a"
    }
    val vpces = VpcEndpointService.Builder
        .create(stack, "VPCES")
        .vpcEndpointServiceLoadBalancers(listOf(nlb))
        .build()
    val zone = PublicHostedZone.Builder
        .create(stack, "PHZ")
        .zoneName("aws-cdk.dev")
        .build()
    val importedZone = PublicHostedZone.fromPublicHostedZoneAttributes(
        stack,
        "ImportedPHZ",
        PublicHostedZoneAttributes.builder()
            .hostedZoneId(zone.hostedZoneId)
            .zoneName(zone.zoneName)
            .build()
    )
    VpcEndpointServiceDomainName(
        stack,
        "EndpointDomain",
        VpcEndpointServiceDomainNameProps.builder()
            .domainName("import-hostedzone.aws-cdk.dev")
            .endpointService(vpces)
            .publicHostedZone(importedZone) // Type mismatch. Required: IPublicHostedZone! Found: IHostedZone
            .build()
    )
}

Possible Solution

  • Change the return type of PublicHostedZone.fromPublicHostedZoneAttributes() method from IHostedZone to IPublicHostedZone. The change should just be a patch/chore, since IPublicHostedZone extends IHostedZone.
  • This also aligns with the design guidelines for from-attributes.
  • Currently, substituting IHostedZone for IPublicHosted works for Typescript since type compatibility is based on structural subtyping. But in nominally-typed languages like Java, this will fail.

I may be able to contribute a PR to fix this 🙂

Additional Information/Context

No response

CDK CLI Version

2.27.0

Framework Version

No response

Node.js Version

16.14.2

OS

macOS

Language

Java

Language Version

Java 11

Other information

Changes from pull-request #19771

@aamielsan aamielsan added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jul 5, 2022
@github-actions github-actions bot added the @aws-cdk/aws-route53 Related to Amazon Route 53 label Jul 5, 2022
@aamielsan
Copy link
Author

As a work-around, we're creating an anonymous class that extends IPublicHostedZone and delegate the methods to the imported public hosted zone with type IHostedZone.

val importedPhz: IHostedZone = PublicHostedZone.fromPublicHostedZoneAttributes(
    stack,
    "ImportedPHZ",
    PublicHostedZoneAttributes.builder()
        .hostedZoneId(zone.hostedZoneId)
        .zoneName(zone.zoneName)
        .build()
)

val phz: IPublicHostedZone = object : IPublicHostedZone {
    override fun getNode(): Node = importedPhz.node
    override fun getEnv(): ResourceEnvironment = importedPhz.env
    override fun getStack(): Stack = importedPhz.stack
    override fun applyRemovalPolicy(policy: RemovalPolicy) = importedPhz.applyRemovalPolicy(policy)
    override fun getHostedZoneArn(): String = importedPhz.hostedZoneArn
    override fun getHostedZoneId(): String = importedPhz.hostedZoneId
    override fun getZoneName(): String = importedPhz.zoneName
}

This works for now since IPublicHostedZone doesn't add any new properties/methods based from this code

@peterwoodworth
Copy link
Contributor

Thanks for reporting this @aamielsan, I've created a PR for this #21007

@peterwoodworth peterwoodworth added p1 effort/small Small work item – less than a day of effort in-progress This issue is being actively worked on. and removed needs-triage This issue or PR still needs to be triaged. labels Jul 6, 2022
@mergify mergify bot closed this as completed in #21007 Jul 8, 2022
mergify bot pushed a commit that referenced this issue Jul 8, 2022
…IPublicHostedZone (#21007)

fixes #21004 


----

### All Submissions:

* [ ] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)?
	* [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link

github-actions bot commented Jul 8, 2022

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

daschaa pushed a commit to daschaa/aws-cdk that referenced this issue Jul 9, 2022
…IPublicHostedZone (aws#21007)

fixes aws#21004 


----

### All Submissions:

* [ ] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)?
	* [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-route53 Related to Amazon Route 53 bug This issue is a bug. effort/small Small work item – less than a day of effort in-progress This issue is being actively worked on. p1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants